comparison 2d_feature_extraction.py @ 6:5bc8cdc17fd0 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_feature_extraction/ commit c86a1b93cb7732f7331a981d13465653cc1a2790
author imgteam
date Wed, 24 Apr 2024 08:11:39 +0000
parents 2436a8807ad1
children
comparison
equal deleted inserted replaced
5:2436a8807ad1 6:5bc8cdc17fd0
1 import argparse 1 import argparse
2 2
3 import giatools.io
3 import numpy as np 4 import numpy as np
4 import pandas as pd 5 import pandas as pd
5 import skimage.feature 6 import skimage.feature
6 import skimage.io
7 import skimage.measure 7 import skimage.measure
8 import skimage.morphology 8 import skimage.morphology
9 import skimage.segmentation 9 import skimage.segmentation
10 10
11 11
55 out_file = args.output_file.name 55 out_file = args.output_file.name
56 add_patch = args.add_roi_patches 56 add_patch = args.add_roi_patches
57 57
58 raw_image = None 58 raw_image = None
59 if args.raw_file is not None: 59 if args.raw_file is not None:
60 raw_image = skimage.io.imread(args.raw_file.name) 60 raw_image = giatools.io.imread(args.raw_file.name)
61 61
62 raw_label_image = skimage.io.imread(label_file) 62 raw_label_image = giatools.io.imread(label_file)
63 63
64 df = pd.DataFrame() 64 df = pd.DataFrame()
65 if label_file_binary: 65 if label_file_binary:
66 raw_label_image = skimage.measure.label(raw_label_image) 66 raw_label_image = skimage.measure.label(raw_label_image)
67 regions = skimage.measure.regionprops(raw_label_image, intensity_image=raw_image) 67 regions = skimage.measure.regionprops(raw_label_image, intensity_image=raw_image)
122 perimeter = df['it'].map(lambda ait: regions[ait].perimeter) 122 perimeter = df['it'].map(lambda ait: regions[ait].perimeter)
123 area = df['it'].map(lambda ait: regions[ait].area) 123 area = df['it'].map(lambda ait: regions[ait].area)
124 df['convexity'] = area / (perimeter * perimeter) 124 df['convexity'] = area / (perimeter * perimeter)
125 125
126 del df['it'] 126 del df['it']
127 df.to_csv(out_file, sep='\t', line_terminator='\n', index=False) 127 df.to_csv(out_file, sep='\t', lineterminator='\n', index=False)