# HG changeset patch # User imgteam # Date 1608767789 0 # Node ID aaac58d830436b1721a40c48174fb590dbddde00 # Parent a84822a0060c43cc68811a855e37b91bba6354bb "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 7391bb4256f49ec30cf38d9438f97e11ec25a115" diff -r a84822a0060c -r aaac58d83043 projective_transformation_points.py --- a/projective_transformation_points.py Fri May 08 05:22:34 2020 -0400 +++ b/projective_transformation_points.py Wed Dec 23 23:56:29 2020 +0000 @@ -42,15 +42,20 @@ return tf_coords[:, ::-1] -def transform(coords, warp_matrix, out): - roi_coords = np.array(pd.read_csv(coords, delimiter="\t")) - trans_matrix = np.array(pd.read_csv(warp_matrix, delimiter="\t", header=None)) +def transform(fn_roi_coords, fn_warp_matrix, fn_out): + data = pd.read_csv(fn_roi_coords, delimiter="\t") + all_data = np.array(data) + + nrows = all_data.shape[0] + ncols = all_data.shape[1] + roi_coords = all_data.take([0,1],axis=1).astype('int64') tol = 10 - moving = np.zeros(np.max(roi_coords,axis=0)+tol, dtype=np.int8) + moving = np.zeros(np.max(roi_coords,axis=0)+tol, dtype=np.uint32) idx_roi_coords = (roi_coords[:,0]-1) * moving.shape[1] + roi_coords[:,1] - 1 - moving.flat[idx_roi_coords] = 1 + moving.flat[idx_roi_coords] = np.transpose(np.arange(nrows)+1) + trans_matrix = np.array(pd.read_csv(fn_warp_matrix, delimiter="\t", header=None)) transP = ProjectiveTransform(matrix=trans_matrix) roi_coords_warped_direct = warp_coords_batch(transP, roi_coords) shape_fixed = np.round(np.max(roi_coords_warped_direct,axis=0)).astype(roi_coords.dtype)+tol @@ -58,19 +63,24 @@ transI = ProjectiveTransform(matrix=np.linalg.inv(trans_matrix)) img_coords_warped = warp_img_coords_batch(transI, shape_fixed) - moving_warped = map_coordinates(moving, img_coords_warped, mode='constant', cval=0) - idx_roi_coords_warped = np.where(moving_warped==1) + moving_warped = map_coordinates(moving, img_coords_warped, order=0, mode='constant', cval=0) + idx_roi_coords_warped = np.where(moving_warped>0) + roi_annots_warped = moving_warped.compress((moving_warped>0).flat) df = pd.DataFrame() + col_names = data.columns.tolist() df['x'] = idx_roi_coords_warped[0] + 1 df['y'] = idx_roi_coords_warped[1] + 1 - df.to_csv(out, index = False, sep="\t") + if ncols>2: + for i in range(2,ncols): + df[col_names[i]] = all_data[:,i].take(roi_annots_warped) + df.to_csv(fn_out, index = False, sep="\t") if __name__ == "__main__": parser = argparse.ArgumentParser(description="Transform coordinates") - parser.add_argument("coords", help="Paste path to .csv with coordinates to transform (tab separated)") - parser.add_argument("warp_matrix", help="Paste path to .csv that should be used for transformation (, separated)") - parser.add_argument("out", help="Paste path to file in which transformed coords should be saved (tab separated)") + parser.add_argument("coords", help="Paste path to .csv with coordinates (and labels) to transform (tab separated)") + parser.add_argument("warp_matrix", help="Paste path to .csv that should be used for transformation (tab separated)") + parser.add_argument("out", help="Paste path to file in which transformed coords (and labels) should be saved (tab separated)") args = parser.parse_args() transform(args.coords, args.warp_matrix, args.out) diff -r a84822a0060c -r aaac58d83043 projective_transformation_points.xml --- a/projective_transformation_points.xml Fri May 08 05:22:34 2020 -0400 +++ b/projective_transformation_points.xml Wed Dec 23 23:56:29 2020 +0000 @@ -1,10 +1,10 @@ - + of input points scikit-image scipy pandas - numpy + numpy tifffile @@ -32,7 +32,7 @@ **What it does** - This tool performs a projective transformation of the input (moving) points. + This tool performs a projective transformation of the input (moving) points (with/without labels). 10.1016/j.jbiotec.2017.07.019