-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add background_removal tool (skimage) #125
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b56cd2
Added new tool for background removal based on skimage
rmassei 580d6a4
Update background_removal.py
rmassei 2ac7b9a
Updated and harmonized the tool xml file, updated creators and test x…
rmassei bf6ece9
Adjusted the python code, changed the test input to a 16bits .tif, up…
rmassei 75c03fd
Add new test for different uint, python script changed to convert out…
rmassei 3ee4097
all trailing white spaces in the python code removed
rmassei 1654c67
fixed help section and test structure
rmassei cd5cad0
Update background_removal.py
rmassei c6b1140
Merge branch 'master' into master
kostrykin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
homepage_url: https://github.com/bmcv | ||
remote_repository_url: https://github.com/BMCV/galaxy-image-analysis/tools/background_removal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import argparse | ||
import warnings | ||
|
||
import numpy as np | ||
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 = convert_image_to_format_of(output_image, image) | ||
skimage.io.imsave(args.output, output_image, plugin="tifffile") | ||
|
||
kostrykin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def convert_image_to_format_of(image, format_image): | ||
""" | ||
Convert the first image to the format of the second image. | ||
""" | ||
if format_image.dtype == image.dtype: | ||
return image | ||
elif format_image.dtype == np.uint8: | ||
return skimage.util.img_as_ubyte(image) | ||
elif format_image.dtype == np.uint16: | ||
return skimage.util.img_as_uint(image) | ||
elif format_image.dtype == np.int16: | ||
return skimage.util.img_as_int(image) | ||
else: | ||
raise ValueError(f'Unsupported image data type: {format_image.dtype}') | ||
|
||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<tool id="background_removal" name="Remove image background" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05"> | ||
<description>with scikit-image</description> | ||
<macros> | ||
<import>creators.xml</import> | ||
<import>tests.xml</import> | ||
<token name="@TOOL_VERSION@">0.24.0</token> | ||
<token name="@VERSION_SUFFIX@">0</token> | ||
</macros> | ||
<creator> | ||
<expand macro="creators/rmassei"/> | ||
</creator> | ||
<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"/> | ||
</outputs> | ||
<tests> | ||
<!-- uint8 tests --> | ||
<test> | ||
<param name="input_image" value="input1_uint8.tif"/> | ||
<param name="filter" value="dog"/> | ||
<param name="radius" value="20"/> | ||
<expand macro="tests/intensity_image_diff" name="output" value="input1_output_dog.tif" ftype="tiff"/> | ||
</test> | ||
<test> | ||
kostrykin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<param name="input_image" value="input3_uint8.tif"/> | ||
<param name="filter" value="top_hat"/> | ||
<param name="radius" value="15"/> | ||
<expand macro="tests/intensity_image_diff" name="output" value="input3_output_tophat.tif" ftype="tiff"/> | ||
</test> | ||
<!-- uint16 tests --> | ||
<test> | ||
<param name="input_image" value="input2_uint16.tif"/> | ||
<param name="filter" value="rolling_ball"/> | ||
<param name="radius" value="20"/> | ||
<expand macro="tests/intensity_image_diff" name="output" value="input2_output_rb.tif" ftype="tiff"/> | ||
</test> | ||
<test> | ||
<param name="input_image" value="input2_uint16.tif"/> | ||
<param name="filter" value="dog"/> | ||
<param name="radius" value="20"/> | ||
<expand macro="tests/intensity_image_diff" name="output" value="input2_output_dog.tif" ftype="tiff"/> | ||
</test> | ||
</tests> | ||
<help> | ||
This tool applies different background removal algorithms to an image: | ||
|
||
- Rolling-ball algorithm | ||
|
||
- Difference of Gaussians | ||
|
||
- Top-hat filter | ||
</help> | ||
<citations> | ||
<citation type="doi">10.1109/MC.1983.1654163</citation> | ||
</citations> | ||
</tool> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../macros/creators.xml |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../macros/tests.xml |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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