Page 1 of 1

Auto white levels & resizing in one go?

Posted: 2018-03-24T09:36:31-07:00
by Norman77
Hi there! :-)

I was following a discussion here on applying auto white levels, but my knowledge is far off from being able to follow it.
From the lab i got histo pics which are too dark. With gimp, i would apply "auto white levels" - "Weißabgleich" in german.
As far as i see, this is a bit more difficult in ImageMagick.

These are tiff images in 3136 × 2352, and i would like to have them in half the size and jpeg (about 80% quality).
The image on the left is what i have, the image to the right is roughly what i want (i used gimp here).

Image

I am sorry, i am no informatician, i am just a chemist who ended up in cancer research.

Maybe someone can throw me a bone on what to type in the console?
Or is there a script maybe even for scientific reference?

Best wishes,

Norman

(Btw. The image is showing a liver sample from a mouse carrying a tumor showing cells adjacent to vessels, which suppress the immune system and help to spread metastasis.)

Re: Auto white levels & resizing in one go?

Posted: 2018-03-24T10:43:51-07:00
by fmw42
I am not sure what GIMP is doing, but I have a script, autotune, that comes close. It is a bash unix shell script using Imagemagick. See my link below.

Input:
Image

Code: Select all

autotone -n cells.png cells_at.png
Image

It has a bit of sharpening, which can be removed if you like by adding -s.

Re: Auto white levels & resizing in one go?

Posted: 2018-03-24T12:01:25-07:00
by Norman77
Wow, thank you very much!

I came across your page before, but was a bit overwhelmed with all these options. :-)
This indeed looks very much like what i need.
How can i include to resize it to half the size and put it in jpg, applying it to all the files in a directory?
There should be some shell mantra which works like

"for i in *.tif; do autotone -s -b $1.jpg..."

but i am no programmer, sadly.

Your script is a big help in any case.
Thank you so much!

Cheers,

Norman

Re: Auto white levels & resizing in one go?

Posted: 2018-03-24T12:46:58-07:00
by fmw42
try this:

Code: Select all

cd
cd /Users/fred/desktop/test1
list=`ls`
for img in $list; do
name=`convert "$img" -format "%t" info:`
convert -quiet $img -resize 50% miff:- | autotone -n - "/Users/fred/desktop/test2/${name}.jpg"
done
Be sure to create your output directory before running this code, since Imagmagick will not create directories. Rename the input directory to where ever you want.

Re: Auto white levels & resizing in one go?

Posted: 2018-03-24T17:39:23-07:00
by fmw42
Here is an alternate Imagemagick only method, which can be processed using mogrify on a whole folder.

Code: Select all

convert cells.png -channel rgb -auto-level cells_autolevel.png
Image

or

Code: Select all

convert cells.png -channel rgb -contrast-stretch 0.1x0.1% cells_cs_0p1.png
Image


To do what you want, see mogrify at https://www.imagemagick.org/Usage/basics/#mogrify

create a new directory for the output

cd input_directory

Code: Select all

mogrify -path path2/output_directory -format tiff -resize 50% -channel rgb -auto-level *.tiff
or

Code: Select all

mogrify -path path2/output_directory -format tiff -resize 50% -channel rgb -contrast-stretch 0.1x0.1% *.tiff
see
https://www.imagemagick.org/script/comm ... auto-level
https://www.imagemagick.org/script/comm ... st-stretch

Re: Auto white levels & resizing in one go?

Posted: 2018-03-24T22:58:20-07:00
by Norman77
Wow, thank you so much for your support!
This is really great, i ppreciate it very much.
I even used mogrify maybe 20 years ago, but i forgot about it at all, not to mention any parameters.
But i will have to do quite some microscopy tasks with students, will need it bad.
So, thanks again!

Cheers,

Norman