diff --git a/cellbin2/contrib/alignment/template_00pt.py b/cellbin2/contrib/alignment/template_00pt.py index 78abf52..1ffa8af 100644 --- a/cellbin2/contrib/alignment/template_00pt.py +++ b/cellbin2/contrib/alignment/template_00pt.py @@ -44,7 +44,7 @@ def registration_image( result = image.trans_image( scale=[1 / self._scale_x, 1 / self._scale_y], - rotate=-self._rotation, + rotate=self._rotation, rot90=self.rot90, offset=self.offset, dst_size=self._register_shape, @@ -87,6 +87,7 @@ def align_stitched(self, moving_image: ChipFeature, ): ) transformed_feature.set_point00(moving_image.point00) + transformed_feature.set_anchor_point(moving_image.anchor_point) transformed_feature.chip_box.set_chip_box(chip_points) transformed_feature.set_template( np.concatenate( @@ -126,7 +127,10 @@ def align_transformed(self, moving_image: ChipFeature): _points = self.get_lt_zero_point(_points) _points = _points[(_points[:, 0] > 0) & (_points[:, 1] > 0)] - px, py = sorted(_points.tolist(), key=lambda x: x[0] + x[1])[0] + chip_box_points[0] + px, py = sorted( + _points.tolist(), + key=lambda x: np.abs(x[0] - moving_image.anchor_point[0]) + np.abs(x[1] - moving_image.anchor_point[1]) + )[0] + chip_box_points[0] self._offset = [moving_image.point00[0] - px, moving_image.point00[1] - py] diff --git a/cellbin2/contrib/param.py b/cellbin2/contrib/param.py index 6319e73..81b53ad 100644 --- a/cellbin2/contrib/param.py +++ b/cellbin2/contrib/param.py @@ -16,6 +16,7 @@ def __init__(self): self._point00: Tuple[int, int] = (0, 0) # xy,相对于芯片而不是矩阵的位置坐标 self._mat: Union[str, np.ndarray, CBImage] = '' # self.ref: List[List, List] = [[]] + self._anchor_point: Tuple[int, int] = (0, 0) # xy, 用于配准前置的辅助锚点 @property def chip_box(self, ): @@ -28,6 +29,14 @@ def set_point00(self, points): if isinstance(points, tuple) and len(points) == 2: self._point00 = points + def set_anchor_point(self, points): + if isinstance(points, tuple) and len(points) == 2: + self._anchor_point = points + + @property + def anchor_point(self, ): + return self._anchor_point + @property def point00(self, ): return self._point00 diff --git a/cellbin2/modules/extract/image_extract.py b/cellbin2/modules/extract/image_extract.py index 87842c1..7f32d1d 100644 --- a/cellbin2/modules/extract/image_extract.py +++ b/cellbin2/modules/extract/image_extract.py @@ -257,6 +257,7 @@ def _pre_registration(self, ): moving_image.set_template(self._channel_image.stitched_template_info) moving_image.set_chip_box(self._channel_image.box_info) moving_image.set_point00(self._param_chip.zero_zero_point) + moving_image.set_anchor_point(tuple(self._param_chip.zero_zero_chip_point)) res = template_00pt.template_00pt_align(moving_image=moving_image, ref=self._param_chip.fov_template, @@ -266,6 +267,8 @@ def _pre_registration(self, ): with open(os.path.join(self.output_path, 'register_00pt.txt'), 'w') as f: f.writelines(f"offset: {res.offset} \n") + # res.register_mat.write(os.path.join(self.output_path, "register_00pt.tif")) + # self._channel_image.update_registration(res) @process_decorator('GiB') diff --git a/cellbin2/utils/stereo_chip.py b/cellbin2/utils/stereo_chip.py index 57e82b0..3aaa000 100644 --- a/cellbin2/utils/stereo_chip.py +++ b/cellbin2/utils/stereo_chip.py @@ -148,8 +148,8 @@ def set_zero_point_info(self, ): points_finish.transpose(1, 0).tolist()) _x = np.array(x_set)[1:] - np.array(x_set)[:-1] _y = np.array(y_set)[1:] - np.array(y_set)[:-1] - zero_x = x_set[np.where(_x == self.fov_template[0][0])[0][0] + 2] - zero_y = y_set[np.where(_y == self.fov_template[0][0])[0][0] + 2] + zero_x = x_set[np.where(_x == max(self.fov_template[0]))[0][0] + 1] + zero_y = x_set[np.where(_x == max(self.fov_template[0]))[0][0] + 1] # 补充00点距芯片角距离 index = np.where(((points_finish[:, 0] == zero_x) & (points_finish[:, 1] == zero_y)) == True)[0][0]