Mercurial > repos > thomaswollmann > color_deconvolution
changeset 0:d7bd56ed3d85 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/color-deconvolution commit b405a7bf071e77b80e314e4a5c340af71fd63adf
author | thomaswollmann |
---|---|
date | Tue, 07 Feb 2017 09:56:10 -0500 |
parents | |
children | e5d95eb1daad |
files | color-deconvolution.xml color_deconvolution.py test-data/galaxyIcon_noText.png |
diffstat | 3 files changed, 167 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/color-deconvolution.xml Tue Feb 07 09:56:10 2017 -0500 @@ -0,0 +1,86 @@ +<tool id="color_deconvolution" name="color-deconvolution" version="0.2"> + <requirements> + <requirement type="package" version="0.12.3" >scikit-image</requirement> + <requirement type="package" version="4.0.0">pillow</requirement> + <requirement type="package" version="0.18.1">scikit-learn</requirement> + <requirement type="package" version="1.11">numpy</requirement> + </requirements> + <description>Color deconvolution</description> + <command> + <![CDATA[ + python "$__tool_directory__/color_deconvolution.py" '$input' '$output' '$convtype' + ]]> + </command> + <inputs> + <param name="input" type="data" format="tiff,png,jpg,bmp" label="Image file with 3 channels"/> + <param name="convtype" type="select" label="Transformation type"> + <option value="pca" selected="True">pca</option> + <option value="xyz2rgb">xyz2rgb</option> + <option value="rgb_from_rbd">rgb_from_rbd</option> + <option value="rgb_from_hdx">rgb_from_hdx</option> + <option value="rgb2hsv">rgb2hsv</option> + <option value="rgb_from_bro">rgb_from_bro</option> + <option value="bpx_from_rgb">bpx_from_rgb</option> + <option value="hed_from_rgb">hed_from_rgb</option> + <option value="rgbcie2rgb">rgbcie2rgb</option> + <option value="hdx_from_rgb">hdx_from_rgb</option> + <option value="xyz2luv">xyz2luv</option> + <option value="rgb2lab">rgb2lab</option> + <option value="hpx_from_rgb">hpx_from_rgb</option> + <option value="rgb_from_fgx">rgb_from_fgx</option> + <option value="rgb_from_gdx">rgb_from_gdx</option> + <option value="lab2xyz">lab2xyz</option> + <option value="rgb_from_hpx">rgb_from_hpx</option> + <option value="lab2rgb">lab2rgb</option> + <option value="rgb2rgbcie">rgb2rgbcie</option> + <option value="bex_from_rgb">bex_from_rgb</option> + <option value="xyz2lab">xyz2lab</option> + <option value="rgb_from_bex">rgb_from_bex</option> + <option value="fgx_from_rgb">fgx_from_rgb</option> + <option value="rbd_from_rgb">rbd_from_rgb</option> + <option value="rgb2hed">rgb2hed</option> + <option value="hed2rgb">hed2rgb</option> + <option value="luv2rgb">luv2rgb</option> + <option value="luv2xyz">luv2xyz</option> + <option value="lch2lab">lch2lab</option> + <option value="rgb2luv">rgb2luv</option> + <option value="ahx_from_rgb">ahx_from_rgb</option> + <option value="rgb_from_hax">rgb_from_hax</option> + <option value="hax_from_rgb">hax_from_rgb</option> + <option value="rgb_from_bpx">rgb_from_bpx</option> + <option value="rgb2xyz">rgb2xyz</option> + <option value="gdx_from_rgb">gdx_from_rgb</option> + <option value="rgb_from_ahx">rgb_from_ahx</option> + <option value="lab2lch">lab2lch</option> + <option value="rgb_from_hed">rgb_from_hed</option> + <option value="bro_from_rgb">bro_from_rgb</option> + <option value="hsv2rgb">hsv2rgb</option> + </param> + </inputs> + <outputs> + <data format="tiff" name="output"/> + </outputs> + <tests> + <test> + <param name="input" value="galaxyIcon_noText.png" /> + <param name="convtype" value="rgb2hsv" /> + <output name="output" ftype="tiff" /> + </test> + </tests> + <help>This tools performs several color deconvolution techniques.</help> + <citations> + <citation type="doi">10.7717/peerj.453</citation> + <citation type="bibtex">@inproceedings{sklearn_api, + author = {Lars Buitinck and Gilles Louppe and Mathieu Blondel and + Fabian Pedregosa and Andreas Mueller and Olivier Grisel and + Vlad Niculae and Peter Prettenhofer and Alexandre Gramfort + and Jaques Grobler and Robert Layton and Jake VanderPlas and + Arnaud Joly and Brian Holt and Ga{\"{e}}l Varoquaux}, + title = {{API} design for machine learning software: experiences from the scikit-learn + project}, + booktitle = {ECML PKDD Workshop: Languages for Data Mining and Machine Learning}, + year = {2013}, + pages = {108--122}, +}</citation> + </citations> +</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/color_deconvolution.py Tue Feb 07 09:56:10 2017 -0500 @@ -0,0 +1,81 @@ +import argparse +import sys +import warnings +import numpy as np +import skimage.io +import skimage.color +import skimage.util +from sklearn.decomposition import PCA + +convOptions = { + 'hed2rgb' : lambda img_raw: skimage.color.hed2rgb(img_raw), + 'hsv2rgb' : lambda img_raw: skimage.color.hsv2rgb(img_raw), + 'lab2lch' : lambda img_raw: skimage.color.lab2lch(img_raw), + 'lab2rgb' : lambda img_raw: skimage.color.lab2rgb(img_raw), + 'lab2xyz' : lambda img_raw: skimage.color.lab2xyz(img_raw), + 'lch2lab' : lambda img_raw: skimage.color.lch2lab(img_raw), + 'luv2rgb' : lambda img_raw: skimage.color.luv2rgb(img_raw), + 'luv2xyz' : lambda img_raw: skimage.color.luv2xyz(img_raw), + 'rgb2hed' : lambda img_raw: skimage.color.rgb2hed(img_raw), + 'rgb2hsv' : lambda img_raw: skimage.color.rgb2hsv(img_raw), + 'rgb2lab' : lambda img_raw: skimage.color.rgb2lab(img_raw), + 'rgb2luv' : lambda img_raw: skimage.color.rgb2luv(img_raw), + 'rgb2rgbcie' : lambda img_raw: skimage.color.rgb2rgbcie(img_raw), + 'rgb2xyz' : lambda img_raw: skimage.color.rgb2xyz(img_raw), + #'rgb2ycbcr' : lambda img_raw: skimage.color.rgb2ycbcr(img_raw), + #'rgb2yiq' : lambda img_raw: skimage.color.rgb2yiq(img_raw), + #'rgb2ypbpr' : lambda img_raw: skimage.color.rgb2ypbpr(img_raw), + #'rgb2yuv' : lambda img_raw: skimage.color.rgb2yuv(img_raw), + #'rgba2rgb' : lambda img_raw: skimage.color.rgba2rgb(img_raw), + 'rgbcie2rgb' : lambda img_raw: skimage.color.rgbcie2rgb(img_raw), + 'xyz2lab' : lambda img_raw: skimage.color.xyz2lab(img_raw), + 'xyz2luv' : lambda img_raw: skimage.color.xyz2luv(img_raw), + 'xyz2rgb' : lambda img_raw: skimage.color.xyz2rgb(img_raw), + #'ycbcr2rgb' : lambda img_raw: skimage.color.ycbcr2rgb(img_raw), + #'yiq2rgb' : lambda img_raw: skimage.color.yiq2rgb(img_raw), + #'ypbpr2rgb' : lambda img_raw: skimage.color.ypbpr2rgb(img_raw), + #'yuv2rgb' : lambda img_raw: skimage.color.yuv2rgb(img_raw), + + 'rgb_from_hed' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_hed), + 'rgb_from_hdx' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_hdx), + 'rgb_from_fgx' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_fgx), + 'rgb_from_bex' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_bex), + 'rgb_from_rbd' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_rbd), + 'rgb_from_gdx' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_gdx), + 'rgb_from_hax' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_hax), + 'rgb_from_bro' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_bro), + 'rgb_from_bpx' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_bpx), + 'rgb_from_ahx' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_ahx), + 'rgb_from_hpx' : lambda img_raw: skimage.color.combine_stains(img_raw, skimage.color.rgb_from_hpx), + + 'hed_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.hed_from_rgb), + 'hdx_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.hdx_from_rgb), + 'fgx_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.fgx_from_rgb), + 'bex_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.bex_from_rgb), + 'rbd_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.rbd_from_rgb), + 'gdx_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.gdx_from_rgb), + 'hax_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.hax_from_rgb), + 'bro_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.bro_from_rgb), + 'bpx_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.bpx_from_rgb), + 'ahx_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.ahx_from_rgb), + 'hpx_from_rgb' : lambda img_raw: skimage.color.separate_stains(img_raw, skimage.color.hpx_from_rgb), + + 'pca' : lambda img_raw: np.reshape(PCA(n_components=3).fit_transform(np.reshape(img_raw, [-1, img_raw.shape[2]])), + [img_raw.shape[0],img_raw.shape[1],-1]) +} + +parser = argparse.ArgumentParser() +parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') +parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)') +parser.add_argument('conv_type', choices=convOptions.keys(), help='conversion type') +args = parser.parse_args() + +img_in = skimage.io.imread(args.input_file.name)[:,:,0:3] +res = convOptions[args.conv_type](img_in) +res[res<-1]=-1 +res[res>1]=1 + +with warnings.catch_warnings(): + warnings.simplefilter("ignore") + res = skimage.util.img_as_uint(res) #Attention: precision loss +skimage.io.imsave(args.out_file.name, res, plugin='tifffile') \ No newline at end of file