# HG changeset patch # User imgteam # Date 1745419062 0 # Node ID aef9911c0d5c74cdae34f7fcbcd4e8d5dd5fdc47 # Parent de611b3b5ae86f6c5bcad29986f0df6c7d112d3e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/points2labelimage/ commit 78614a9010c2ca0e1fa5973639c05ab74bcdb148 diff -r de611b3b5ae8 -r aef9911c0d5c points2label.py --- a/points2label.py Fri Sep 27 17:41:21 2024 +0000 +++ b/points2label.py Wed Apr 23 14:37:42 2025 +0000 @@ -33,6 +33,17 @@ radius_list = [0] * len(pos_x_list) try: + width_column = giatools.pandas.find_column(df, ['width', 'WIDTH']) + height_column = giatools.pandas.find_column(df, ['height', 'HEIGHT']) + width_list = df[width_column] + height_list = df[height_column] + assert len(pos_x_list) == len(width_list) + assert len(pos_x_list) == len(height_list) + except KeyError: + width_list = [0] * len(pos_x_list) + height_list = [0] * len(pos_x_list) + + try: label_column = giatools.pandas.find_column(df, ['label', 'LABEL']) label_list = df[label_column] assert len(pos_x_list) == len(label_list) @@ -45,7 +56,7 @@ pos_x_list = df[0].round().astype(int) pos_y_list = df[1].round().astype(int) assert len(pos_x_list) == len(pos_y_list) - radius_list = [0] * len(pos_x_list) + radius_list, width_list, height_list = [[0] * len(pos_x_list)] * 3 label_list = list(range(1, len(pos_x_list) + 1)) # Optionally swap the coordinates @@ -53,7 +64,9 @@ pos_x_list, pos_y_list = pos_y_list, pos_x_list # Perform the rasterization - for y, x, radius, label in zip(pos_y_list, pos_x_list, radius_list, label_list): + for y, x, radius, width, height, label in zip( + pos_y_list, pos_x_list, radius_list, width_list, height_list, label_list, + ): if fg_value is not None: label = fg_value @@ -61,10 +74,23 @@ raise IndexError(f'The point x={x}, y={y} exceeds the bounds of the image (width: {shape[1]}, height: {shape[0]})') # Rasterize circle and distribute overlapping image area - if radius > 0: - mask = np.ones(shape, dtype=bool) - mask[y, x] = False - mask = (ndi.distance_transform_edt(mask) <= radius) + # Rasterize primitive geometry + if radius > 0 or (width > 0 and height > 0): + + # Rasterize circle + if radius > 0: + mask = np.ones(shape, dtype=bool) + mask[y, x] = False + mask = (ndi.distance_transform_edt(mask) <= radius) + else: + mask = np.zeros(shape, dtype=bool) + + # Rasterize rectangle + if width > 0 and height > 0: + mask[ + y:min(shape[0], y + width), + x:min(shape[1], x + height) + ] = True # Compute the overlap (pretend there is none if the rasterization is binary) if fg_value is None: diff -r de611b3b5ae8 -r aef9911c0d5c points2label.xml --- a/points2label.xml Fri Sep 27 17:41:21 2024 +0000 +++ b/points2label.xml Wed Apr 23 14:37:42 2025 +0000 @@ -3,7 +3,7 @@ creators.xml tests.xml - 0.4 + 0.4.1 0 @@ -46,7 +46,7 @@ - + @@ -56,7 +56,7 @@ - + @@ -66,7 +66,7 @@ - + @@ -76,7 +76,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -96,6 +96,16 @@ + + + + + + + + + + @@ -113,6 +123,8 @@ - ``pos_y`` or ``POS_Y``: This column corresponds to the Y coordinates. - If a ``radius`` or ``RADIUS`` column is present, then the points will be rasterized as circles of the corresponding radii. + - If ``width`` or ``WIDTH`` and ``height`` or ``HEIGHT`` columns are present, then the points will be rasterized + as rectangles of the corresponding size. - If a ``label`` or ``LABEL`` column is present, then the corresponding labels will be used for rasterization (unless "Produce binary image" is activated). Different points are allowed to use the same label. diff -r de611b3b5ae8 -r aef9911c0d5c test-data/input4.tsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/input4.tsv Wed Apr 23 14:37:42 2025 +0000 @@ -0,0 +1,4 @@ +pos_x pos_y width height label +20 20 40 40 1 +50 50 30 40 2 +150 50 60 40 3 diff -r de611b3b5ae8 -r aef9911c0d5c test-data/output4.tif Binary file test-data/output4.tif has changed