I wonder if you can help confirm something for me, we've a website using imagemagick to basic automatically level/brighten/color correct images to be used for print, but it's incredibly slow. Essentially the person that set this up has now left, so it's down to me to try and figure out how to get the site running faster(in relation to the image processing.)
Now I've been speaking to the developers trying to get some information on what is exactly happening and I've been given the response below:
Now the value above get passed into this command which does the image manipulation:The process is as follows, though the implementation of this is python unless otherwise stated.
1. The histogram is generated using the following imagemagick command:
convert -shave 3% -sample 100 -format %c rgb.jpg histogram:info:-
2. You'll see that this produces output in the format:
"3: (121,121,145, 96) #79799160 cmyk(121,121,145,96)"
The first 5 integers are parsed from this, i.e.
"3 121 121 145 96"
Where 3 is the pixel count of occurrences of CMYK (121,121,145,96).
These parsed integers are used to create histograms of each colour.
3. The histogram for each colour is sorted in ascending value of intensity.
4. A threshold value is generated for the image using the total number of pixels multiplied by 0.4.
4.1. We iterate over the sorted histogram of a colour adding the number of pixels of each intensity to a running total.
4.2. When the running total is greater than the threshold value calculated at (4) a cutoff value (c_v) for this colour is calculated using the current intensity divided by 256.
5. The cutoff value for each colour is used to generate the clipping formulae for imagemagick e.g. (1/c_v)*u+1-(1/c_v) These are the values you see in the commands I sent over.
Now I've tried both commands above on my desktop, the second seems reasonably fast.The command generated using the CMYK histograms:
convert -channel Y -fx "(1/0.965)*u+1-(1/0.965)" -channel C -fx "(1/0.598)*u+1-(1/0.598)" -channel M -fx "(1/0.793)*u+1-(1/0.793)" -channel K -fx "(1/0.988)*u+1-(1/0.988)" ./cmyk.jpg ./cmyk_adjusted.jpg
but the first, this one:
convert -shave 3% -sample 100 -format %c rgb.jpg histogram:info:-
takes absolutely ages, can vary between 6 and 28 seconds generating all the values(it spits out thousands CMYk values).
So my instinct is that this is where the bottleneck is happening. Does that sound about right?
Now, i've a few questions. Is there any way to speed up the histogram analysis to be able to generate the numbers to pass into the second command?
Does the above process sound about the correct way to be doing things, or should I be looking at something else?
Essentially the place where the above happens, is when a user selects an image and it runs this process there and then, unfortunately I think that this will need to stay as we handle loads of images, but only a small percentage of images get used in generating print.
Sorry if my message above seems abit confusing, but I'm a complete beginner when it comes to imagemagick, I can run simple commands through a command prompt, but that's about it.
I guess what I'm really asking for above is:
a. Is there a faster way to do the histogram analysis?
b. if not are there other processes I should be looking at that will do the same as the above, but run faster(the ultimate goal here is to speed up the end user experience on the system(I know the above isn't perfect from an image manipulation stand point but consider the crap that gets feed into the system, i does help stave of the worst of our problem))
sorry all for the long vague post, but if you have any thoughts on the above I'd be delighted to hear them.
Thanks
Joe