Skip to content

Commit

Permalink
# Pre registration, start-up!
Browse files Browse the repository at this point in the history
  • Loading branch information
lizepeng1 committed Dec 5, 2024
1 parent 72ffefb commit caa2bc1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions cellbin2/contrib/alignment/template_00pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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]

Expand Down
9 changes: 9 additions & 0 deletions cellbin2/contrib/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ):
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions cellbin2/modules/extract/image_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions cellbin2/utils/stereo_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit caa2bc1

Please sign in to comment.