Auto white levels & resizing in one go?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Norman77
Posts: 3
Joined: 2018-03-24T09:05:19-07:00
Authentication code: 1152

Auto white levels & resizing in one go?

Post 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.)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Auto white levels & resizing in one go?

Post 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.
Norman77
Posts: 3
Joined: 2018-03-24T09:05:19-07:00
Authentication code: 1152

Re: Auto white levels & resizing in one go?

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Auto white levels & resizing in one go?

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Auto white levels & resizing in one go?

Post 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
Norman77
Posts: 3
Joined: 2018-03-24T09:05:19-07:00
Authentication code: 1152

Re: Auto white levels & resizing in one go?

Post 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
Post Reply