deepimagej / deepimagej-plugin

The ImageJ plugin to run deep-learning models
https://deepimagej.github.io/deepimagej/
BSD 2-Clause "Simplified" License
86 stars 13 forks source link

fixing check rgb for image scaling macro #25

Closed pr4deepr closed 2 years ago

pr4deepr commented 3 years ago

Hi @esgomezm

You can do a quick fix for the per_sample_scale_range.ijm macro where it checks if the image if its RGB. You can use eval() in ImageJ Macro to run the javascript code for checking if its RGB. I know flag is supposed to be 1 or 0 :), but I just kept it the same for simplicity. Let me know if you want me to send a pull request or anything. I'm not sure where to though.

//script returns 4 if its rgb: https://imagej.nih.gov/ij/developer/api/ij/ij/ImagePlus.html#getType()
flag_rgb=eval("script", "importClass(Packages.ij.IJ);\nIJ.getImage().getType()");

// Convert the RGB image as a stack of slices so it processes the intensity of each slice.
if (flag_rgb==4){
    run("Make Composite");
    run("Stack to Images");
    run("Concatenate...", "  title=stack image1=[Red] image2=[Green] image3=[Blue]");
}

At line 102:

// EXECUTE THE FUNCTION TO THE WHOLE IMAGE
percentile_normalization(min_percentile, max_percentile, nBins);
// Convert the slices into channel to avoid confussion between 3D and multichannel images.
if (flag_rgb==4){
    run("Properties...", "channels=3 slices=1 frames=1 pixel_width=1.0000 pixel_height=1.0000 voxel_depth=1.0000");
}

Cheers Pradeep

esgomezm commented 2 years ago

Hi @pr4deepr

Thank you for the suggestion. We implemented the following: https://github.com/deepimagej/imagej-macros/blob/master/bioimage.io/per_sample_scale_range.ijm#L31

I hope it works