diff --git a/tools/2d_simple_filter/filter.xml b/tools/2d_simple_filter/filter.xml index 56922c56..868930e8 100644 --- a/tools/2d_simple_filter/filter.xml +++ b/tools/2d_simple_filter/filter.xml @@ -79,8 +79,8 @@ Below, we use an assertion in addition to the `image_diff` comparison, to ensure that the range of values is preserved. The motiviation behind this is that the expectation images are usually checked visually, which means that the `image_diff` comparison is likely to ensure that the brightness of - the image is preserved, thus it's good to double-check the range of values (hence the large value - for `eps`). This also concerns the median filter. + the image is correct, thus it's good to double-check the range of values (hence the comparably large + value for `eps`). This also concerns the median filter. --> diff --git a/tools/concat_channels/concat_channels.py b/tools/concat_channels/concat_channels.py index 903092f9..2b041dbb 100644 --- a/tools/concat_channels/concat_channels.py +++ b/tools/concat_channels/concat_channels.py @@ -6,28 +6,38 @@ import skimage.util -def concat_channels(input_image_paths, output_image_path, axis): +def concat_channels(input_image_paths, output_image_path, axis, preserve_values): images = [] for image_path in input_image_paths: + raw_image = skimage.io.imread(image_path) if len(raw_image.shape) == 2: if axis == 0: raw_image = [raw_image] else: raw_image = np.expand_dims(raw_image, 2) + + # Preserve values: Convert to `float` dtype without changing the values + if preserve_values: + raw_image = raw_image.astype(float) + + # Preserve brightness: Scale values to 0..1 + else: + raw_image = skimage.util.img_as_float(raw_image) + images.append(raw_image) + + # Do the concatenation and save res = np.concatenate(images, axis) - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - res = skimage.util.img_as_uint(res) # Attention: precision loss - skimage.io.imsave(output_image_path, res, plugin='tifffile') + skimage.io.imsave(output_image_path, res, plugin='tifffile') if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument('input_files', type=argparse.FileType('r'), nargs='+', help='input file') - parser.add_argument('-o', dest='out_file', type=argparse.FileType('w'), help='out file (TIFF)') - parser.add_argument('--axis', dest='axis', type=int, default=0, choices=[0, 2], help='concatenation axis') + parser.add_argument('input_files', type=argparse.FileType('r'), nargs='+') + parser.add_argument('-o', dest='out_file', type=argparse.FileType('w')) + parser.add_argument('--axis', dest='axis', type=int, default=0, choices=[0, 2]) + parser.add_argument('--preserve_values', default=False, action='store_true') args = parser.parse_args() - concat_channels([x.name for x in args.input_files], args.out_file.name, args.axis) + concat_channels([x.name for x in args.input_files], args.out_file.name, args.axis, args.preserve_values) diff --git a/tools/concat_channels/concat_channels.xml b/tools/concat_channels/concat_channels.xml index 0269a885..871a6452 100644 --- a/tools/concat_channels/concat_channels.xml +++ b/tools/concat_channels/concat_channels.xml @@ -1,5 +1,12 @@ - + + + creators.xml + tests.xml + + + + operation_3443 @@ -7,40 +14,71 @@ galaxy_image_analysis - scikit-image - numpy - tifffile + scikit-image + numpy + tifffile - - - + + ]]> - - - - + + + + + + + + + + + + + - + - + + + + + - **What it does** - This tool concatenates images. + **Concatenates images along arbitrary axes.** + + This can be used, for example, to spatially concatenate images, or along their channels. + + This tool either preserves the image brightness, or the range of values. + In general, both cannot be preserved when concatenating images of different pixel types (e.g., uint8 and uint16). + 10.1016/j.jbiotec.2017.07.019 diff --git a/tools/concat_channels/creators.xml b/tools/concat_channels/creators.xml new file mode 120000 index 00000000..5d2b71e0 --- /dev/null +++ b/tools/concat_channels/creators.xml @@ -0,0 +1 @@ +../../macros/creators.xml \ No newline at end of file diff --git a/tools/concat_channels/test-data/sample1.png b/tools/concat_channels/test-data/input1_uint8.png similarity index 100% rename from tools/concat_channels/test-data/sample1.png rename to tools/concat_channels/test-data/input1_uint8.png diff --git a/tools/concat_channels/test-data/input2_float.tiff b/tools/concat_channels/test-data/input2_float.tiff new file mode 100644 index 00000000..8aee4180 Binary files /dev/null and b/tools/concat_channels/test-data/input2_float.tiff differ diff --git a/tools/concat_channels/test-data/out.tiff b/tools/concat_channels/test-data/out.tiff deleted file mode 100644 index 0bc85f46..00000000 Binary files a/tools/concat_channels/test-data/out.tiff and /dev/null differ diff --git a/tools/concat_channels/test-data/res.tiff b/tools/concat_channels/test-data/res.tiff deleted file mode 100644 index 7c31f754..00000000 Binary files a/tools/concat_channels/test-data/res.tiff and /dev/null differ diff --git a/tools/concat_channels/test-data/res_preserve_brightness.tiff b/tools/concat_channels/test-data/res_preserve_brightness.tiff new file mode 100644 index 00000000..8996b403 Binary files /dev/null and b/tools/concat_channels/test-data/res_preserve_brightness.tiff differ diff --git a/tools/concat_channels/test-data/res_preserve_values.tiff b/tools/concat_channels/test-data/res_preserve_values.tiff new file mode 100644 index 00000000..bb93d3f7 Binary files /dev/null and b/tools/concat_channels/test-data/res_preserve_values.tiff differ diff --git a/tools/concat_channels/test-data/sample2.png b/tools/concat_channels/test-data/sample2.png deleted file mode 100644 index 95d78dc6..00000000 Binary files a/tools/concat_channels/test-data/sample2.png and /dev/null differ diff --git a/tools/concat_channels/tests.xml b/tools/concat_channels/tests.xml new file mode 120000 index 00000000..e20d710a --- /dev/null +++ b/tools/concat_channels/tests.xml @@ -0,0 +1 @@ +../../macros/tests.xml \ No newline at end of file