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?".
I'm trying to do some grading of scans of microfilm (350,000+). The scanner has output indexed colour (greyscale) scans. My problem is that some of the images are very dark(1%) and about 20% could use some degree of lightening. I've worked through grouping the images by appearance using ImageJ and then determined a levels adjustment for each group using Photoshop. Having sorted out the settings I'm now looking to automate the processing with ImageMagick. The adjustments I'm making are substantial increases in gamma with some slight tweaks to black levels to deal with the very dark scans.
Problem 1: No matter what method of greyscale conversion I use I can't get a 1:1 conversion for the pixel values (RGB are all the same) The differences are minor but as I'm working on a very small range of low pixel values, having a few indexed colours drop to 0 is significant.
-set colorspace Gray -separate -evaluate-sequence Mean
Problem 2: My levels adjustments look very different to what I get with Photoshop. I've tried 0-255 and % for black/white levels and even a separate gamma adjustment before/after levels. (gamma adjustments in the order of 2.8 - 4)
I'm working with the latest IM version on Win7 x64. Any advice/suggestions would be welcomed
I am having some trouble understanding what you are doing and what you want. Please upload an example image to some free hosting service and put the URL here. If you have an example result, post that also and tell us what is wrong.
If your image is already grayscale, then why do you need to convert to grayscale again?
Are you trying to get an overall average grayscale value for the whole image?
For automatic adjustment try a combination of -auto-gamma -auto-level or the reverse order.
try this using -contrast-stretch and -level. IM needs values in quantum range or percent. So I always convert to percent, since I do not know what your quantum range is for your compile of IM. PS always provides value in the range 0 to 255. As I recall PS levels uses default clip values of 0.01%, but I might remember wrong and it could be 0.015%. That is why I have -contrast stretch there.
Unix syntax. (Sorry I do not know how to specify variables in Windows syntax, but you can substitute into the last convert with just the values bp=7.84314; wp=58.8235;)
The TIFFs are indexed colour (correction: oddly a mix of indexed and greyscale)... visually the same but I'd prefer greyscale. I hadn't tried the auto options as it wasn't that successful in Photoshop but the one image I tested looked promising with IM. I'll do some further testing across the range of contrasts to see what it does. I might run a second tweak but that won't be as severe an adjustment. Thanks
fmw42 wrote: ↑2017-08-03T18:08:50-07:00
try this using -contrast-stretch and -level. IM needs values in quantum range or percent. So I always convert to percent, since I do not know what your quantum range is for your compile of IM. PS always provides value in the range 0 to 255. As I recall PS levels uses default clip values of 0.01%, but I might remember wrong and it could be 0.015%. That is why I have -contrast stretch there.
Thanks Fred... I'm a bit rusty on IM usage and wasn't accounting for IM's quantum range. Always using % is a good idea. I reset Photoshop's clipping to 0 so the linear stretch is the same but I wasn't getting consistent quality on auto contrast adjustments. I prefer IM in these situations as it's much faster loading/saving images which is a big factor with large numbers of images.
ozbigben wrote:The value for the last gamma adjustment is conditional on the median density of the original image. 2.2 if median < 128 or 1.2 if median >=128
IM doesn't have a built-in calculator for median. It can be done by finding the 50% level of a cumulative histogram.
Thanks for the suggestions. I've done a test run on all of the images and it's worked pretty well. There are still a few other exceptions with low contrast images. I have to figure out a way to classify these first but it's looking like a combination of median, mean and stdev. I've got an Ubuntu machine now so that should give us some extra options.