Mercurial > repos > imgteam > labelimage2points
comparison labelimage2points.py @ 2:3b7460735223 draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
| author | imgteam |
|---|---|
| date | Mon, 13 Nov 2023 22:11:16 +0000 |
| parents | 07525a7d9ea0 |
| children |
comparison
equal
deleted
inserted
replaced
| 1:07525a7d9ea0 | 2:3b7460735223 |
|---|---|
| 1 import argparse | 1 import argparse |
| 2 import sys | 2 |
| 3 import numpy as np | |
| 3 import pandas as pd | 4 import pandas as pd |
| 4 import skimage.io | 5 import skimage.io |
| 5 from skimage.measure import label | |
| 6 from skimage.data import checkerboard | |
| 7 import numpy as np | |
| 8 | 6 |
| 9 | |
| 10 | 7 |
| 11 def labelimage2points(input_file): | 8 def labelimage2points(input_file): |
| 12 img_in = skimage.io.imread(input_file) | 9 img_in = skimage.io.imread(input_file) |
| 13 | 10 |
| 14 #amount of regions | 11 # amount of regions |
| 15 amount_label = np.max(img_in) | 12 amount_label = np.max(img_in) |
| 16 | 13 |
| 17 # iterate over all regions in order to calc center of mass | 14 # iterate over all regions in order to calc center of mass |
| 18 center_mass = [] | 15 center_mass = [] |
| 19 for i in range(1,amount_label+1): | 16 for i in range(1, amount_label + 1): |
| 20 #get coordinates of region | 17 # get coordinates of region |
| 21 coord = np.where(img_in==i) | 18 coord = np.where(img_in == i) |
| 22 # be carefull with x,y coordinates | 19 # be carefull with x,y coordinates |
| 23 center_mass.append([np.mean(coord[1]),np.mean(coord[0])]) | 20 center_mass.append([np.mean(coord[1]), np.mean(coord[0])]) |
| 24 | 21 |
| 25 #make data frame of detections | 22 # make data frame of detections |
| 26 out_dataFrame = pd.DataFrame(center_mass) | 23 out_dataFrame = pd.DataFrame(center_mass) |
| 27 | 24 |
| 28 | 25 # return |
| 29 #return | 26 return out_dataFrame |
| 30 return(out_dataFrame) | |
| 31 | 27 |
| 32 | 28 |
| 33 if __name__ == "__main__": | 29 if __name__ == "__main__": |
| 34 parser = argparse.ArgumentParser() | 30 parser = argparse.ArgumentParser() |
| 35 parser.add_argument('input_file', help='input file') | 31 parser.add_argument('input_file', help='input file') |
| 36 parser.add_argument('out_file', help='out file (CSV)') | 32 parser.add_argument('out_file', help='out file (CSV)') |
| 37 | 33 |
| 38 args = parser.parse_args() | 34 args = parser.parse_args() |
| 39 input_file = args.input_file | 35 input_file = args.input_file |
| 40 out_file = args.out_file | 36 out_file = args.out_file |
| 41 | 37 |
| 42 #TOOL | 38 # TOOL |
| 43 out_dataFrame = labelimage2points(input_file) | 39 out_dataFrame = labelimage2points(input_file) |
| 44 | 40 |
| 45 #Print to csv file | 41 # Print to csv file |
| 46 out_dataFrame.to_csv(out_file, index=False, header=False, sep="\t") | 42 out_dataFrame.to_csv(out_file, index=False, header=False, sep="\t") |
