Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tools/background_removal/.shed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
categories:
- Imaging
description: Background removal filters using scikit-image
long_description: Tool to perform a background removal using 1) Rolling-Ball Algorithm, 2) Difference of Gaussians and 3) Top-Hat Filter
name: background_removal
owner: ufz

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the owner is wrong, we can only push to imgteam

homepage_url: https://github.com/bmcv
remote_repository_url: https://github.com/BMCV/galaxy-image-analysis/tools/background_removal
44 changes: 44 additions & 0 deletions tools/background_removal/background_removal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import argparse
import warnings


import skimage.io
from skimage.filters import difference_of_gaussians
from skimage.io import imread
from skimage.morphology import disk, white_tophat
from skimage.restoration import rolling_ball


def process_image(args):
image = imread(args.input_image)

if args.filter == "rolling_ball":
background_rolling = rolling_ball(image, radius=args.radius)
output_image = image - background_rolling

elif args.filter == "dog":
output_image = difference_of_gaussians(image, low_sigma=0, high_sigma=args.radius)

elif args.filter == "top_hat":
output_image = white_tophat(image, disk(args.radius))

with warnings.catch_warnings():
output_image = skimage.util.img_as_uint(output_image)
Comment thread
kostrykin marked this conversation as resolved.
Outdated
skimage.io.imsave(args.output, output_image, plugin="tifffile")

Comment thread
kostrykin marked this conversation as resolved.

def main():
parser = argparse.ArgumentParser(description="Background removal script using skiimage")
parser.add_argument('input_image', help="Input image path")
parser.add_argument('filter', choices=['rolling_ball', 'dog', 'top_hat'],
help="Background removal algorithm")
parser.add_argument('radius', type=float, help="Radius")
parser.add_argument('output', help="Output image path")

args = parser.parse_args()
process_image(args)


if __name__ == '__main__':
main()

55 changes: 55 additions & 0 deletions tools/background_removal/background_removal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<tool id="background_removal" name="Background Removal" version="0.1">
Comment thread
rmassei marked this conversation as resolved.
Outdated
Comment thread
kostrykin marked this conversation as resolved.
Outdated
<description>with scikit-image</description>
Comment thread
kostrykin marked this conversation as resolved.
Outdated
<requirements>
<requirement type="package" version="0.24.0">scikit-image</requirement>
</requirements>
<command detect_errors="aggressive">
<![CDATA[
python "$__tool_directory__/background_removal.py" $input_image $filter $radius $output
]]>
</command>
<inputs>
<param name="input_image" type="data" format="tiff, jpg, jpeg, png, tif" label="Input Image"/>
<param name="filter" type="select" label="Select Filter">
<option value="rolling_ball">Rolling-Ball Algorithm</option>
<option value="dog">Difference of Gaussians</option>
<option value="top_hat">Top-Hat Filter</option>
</param>
<param name="radius" type="float" label="Radius" value="20"/>
</inputs>
<outputs>
<data name="output" format="tiff" label="Background Substraction Output"/>
Comment thread
kostrykin marked this conversation as resolved.
Outdated
</outputs>
<tests>
<test>
Comment thread
kostrykin marked this conversation as resolved.
<param name="input_image" value="img.png"/>
<param name="filter" value="rolling_ball"/>
<param name="radius" value="20"/>
<output name="output" value="out_rolling_ball.tiff" ftype="tiff"/>
Comment thread
kostrykin marked this conversation as resolved.
Outdated
</test>
<test>
<param name="input_image" value="img.png"/>
<param name="filter" value="dog"/>
<param name="radius" value="20"/>
<output name="output" value="out_dog.tiff" ftype="tiff"/>
</test>
<test>
<param name="input_image" value="sample.tif"/>
Comment thread
kostrykin marked this conversation as resolved.
Outdated
<param name="filter" value="top_hat"/>
<param name="radius" value="15"/>
<output name="output" value="out_top_hat.tiff" ftype="tiff"/>
</test>
</tests>
<help>
This tools applied different background removal algorithm to the image:

- Rolling-Ball Algorithm

- Difference of Gaussians

- Top-Hat Filter
Comment thread
kostrykin marked this conversation as resolved.
Outdated
</help>
<citations>
<citation type="doi">https://haesleinhuepf.github.io/BioImageAnalysisNotebooks/18_image_filtering/03_background_removal.html</citation>
Comment thread
kostrykin marked this conversation as resolved.
Outdated
</citations>
</tool>
Binary file added tools/background_removal/test-data/img.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/background_removal/test-data/out_dog.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tools/background_removal/test-data/sample.tif
Binary file not shown.