# HG changeset patch # User imgteam # Date 1549740977 18000 # Node ID 39e6d6a842579885a355d50ae21dae2dc1d092b3 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581 diff -r 000000000000 -r 39e6d6a84257 labelimage2points.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/labelimage2points.py Sat Feb 09 14:36:17 2019 -0500 @@ -0,0 +1,46 @@ +import argparse +import sys +import pandas as pd +import skimage.io +from skimage.measure import label +from skimage.data import checkerboard +import numpy as np + + + +def labelimage2points(input_file): + img_in = skimage.io.imread(input_file) + + #amount of regions + amount_label = np.max(img_in) + + # iterate over all regions in order to calc center of mass + center_mass = [] + for i in range(1,amount_label+1): + #get coordinates of region + coord = np.where(img_in==i) + # be carefull with x,y coordinates + center_mass.append([np.mean(coord[1]),np.mean(coord[0])]) + + #make data frame of detections + out_dataFrame = pd.DataFrame(center_mass) + + + #return + return(out_dataFrame) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('input_file', help='input file') + parser.add_argument('out_file', help='out file (CSV)') + + args = parser.parse_args() + input_file = args.input_file + out_file = args.out_file + + #TOOL + out_dataFrame = labelimage2points(input_file) + + #Print to csv file + out_dataFrame.to_csv(out_file, index=False, header=False, sep="\t") diff -r 000000000000 -r 39e6d6a84257 labelimage2points.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/labelimage2points.xml Sat Feb 09 14:36:17 2019 -0500 @@ -0,0 +1,32 @@ + + Converts label image to points + + scikit-image + pandas + + + + + + + + + + + + + + + + + + **What it does** + + Calculates the center of mass for all differently colored regions in the image. + + + 10.1016/j.jbiotec.2017.07.019 + + diff -r 000000000000 -r 39e6d6a84257 test-data/label.tif Binary file test-data/label.tif has changed diff -r 000000000000 -r 39e6d6a84257 test-data/points.tsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/points.tsv Sat Feb 09 14:36:17 2019 -0500 @@ -0,0 +1,1 @@ +16.0 19.5