Reputation: 1390
I am trying to recreate Gimp's AutoInputLevels (Colors>Levels>AutoInputLevels) in Imagemagick (need to batch process 1000 files). This is for an infrared image. I tried contrast_stretch, normalize and auto level, but they didn't help. Any suggestions?
Thanks.
Edit: I won't be able to provide the representative images. However, when I say they didn't help, I am using other operations in GIMP. Doing the same (auto level and hard_light in ImageMagick) are not providing equivalent results.
Upvotes: 1
Views: 261
Reputation: 53154
Adding to @Mark Setchell's answer, I can tweak it a bit and get close using:
Input:
convert redhat.jpg -channel rgb -contrast-stretch 0.6%x0.6% im.png
ImageMagick Result:
GIMP AutoInputLevels Result:
And get a numerical comparison:
compare -metric rmse gimp.png im.png null:
363.484 (0.00554641)
which is about 0.5% difference.
Upvotes: 2
Reputation: 207660
As you didn't provide a representative image, or expected result, I synthesised an image with three different distributions of red, green and blue pixels, using code like this:
#!/usr/bin/env python3
from PIL import Image
import numpy as np
w, h = 640, 480
# Synthesize red channel, mu=64, sigma=3
r = np.random.normal(64, 3, size=h*w)
# Synthesize green channel, mu=128, sigma=10
g = np.random.normal(128, 10, size=h*w)
# Synthesize blue channel, mu=192, sigma=6
b = np.random.normal(192, 6, size=h*w)
# Merge channels to RGB and round
RGB = np.dstack((r,g,b)).reshape((h,w,3)).astype(np.uint8)
# Save
Image.fromarray(RGB).save('result.png')
Then I applied the GIMP AutoInputLevels contrast stretch that you are asking about, and saved the result. The resulting histogram is:
which seems to show that the black-point and white-point levels have been set independently for each channel. So, in ImageMagick I guess you would want to separate the channels, apply some contrast-stretch to each channel independently and then recombine the channels along these lines:
magick input.png -separate -contrast-stretch 0.35%x0.7% -combine result.png
If you provide representative input and output images, you may get a better answer.
Upvotes: 0