Page 1 of 1

Problems with Convert

Posted: 2010-01-16T09:42:54-07:00
by JKEngineer
I am using ImageMagick-6.5.8-Q16-windows-Portable-static on Win XP.
I have put files worked with at: http://www.kleinfeldtechnical.com/im for reference.

I created a small image with gray values, greyscale.gif, which ranges from a level of 94 to 255. It is used as the starting point for the testing I did. I ran various options, creating a .pgm file as well to examine the pixel values. The file testandnotes.txt has the history of my tests and notes. I used it as a .bat file, remarking out old commands as I tried new ones.
Image greyscale.gif
I am trying to rescale some scientific images in the long run.

I have tried some manipulations with convert (math function) and with convert (level functions).
Some of these worked as expected. Others would not work at all or gave unexpected results. Any help in guiding me to get these to work the way I think they should, or, more likely, changing my expectations would be appreciated.

Here's a summary of what I tried and where I am having trouble:
for convert math funciton : Multiply and Divide worked as expected, although limited by the 0-255 range available in the image. Add and Subtract did not work as expected. I used pure numbers in the Add and Subtract commands, not %numbers. The commands had no effect at all. Here is the code I used:

Code: Select all

convert greyscale.gif -evaluate divide 2 gover2.gif
convert greyscale.gif -evaluate multiply 2 gtimes2.gif
convert greyscale.gif -evaluate add 25 gplus25.gif
convert greyscale.gif -evaluate subtract 50 gscale-min50.gif
And here is a sample line of code I used to generate the .pgm files.

Code: Select all

convert gscale-min50.gif -colorspace gray -compress none -depth 8 gscale-min50.pgm
Do the Add and Subtract options on convert work? Do they require %number? If using a % is it of the range available (0-255) or of the range in the particular image (94-255 for mine) or does it relate to the histogram?

In reading further, I realized that the Convert -level function would be a better approach to rescaling the images I am planning on adjusting. I also am having similar problems getting this to work.

Here are the commands I tried, with the result I got following the command:

Code: Select all

convert greyscale.gif -level 94,255 gscale-level94-255.gif  --this creates an all white image (255)

convert greyscale.gif -level 100,255 gscale-level100-255.gif  --this creates an all white image (255)

convert greyscale.gif -level 100 gscale-level100-def.gif -- this had no effect

convert greyscale.gif -level 50,255 gscale-level50-255.gif  --this creates an all white image (255)

convert greyscale.gif -level 36.9% gscale-level36pct.gif -- this had no effect

convert greyscale.gif -level 36.9,100% gscale-level36-100pct.gif  --this creates an all white image (255)

convert greyscale.gif -level 36.9%,100% gscale-level36pct-100pct.gif  -- this had no effect
The last three tries above used 36.9% as the black_point. I derived this as 94/255, treating the % as related to the scale, not as related to the histogram or distribution of the pixels in the image. Is this the correct interpretation of the %?

All guidance is much appreciated.
JK

Re: Problems with Convert

Posted: 2010-01-16T11:44:35-07:00
by el_supremo
The only thing I can suggest is that you're running into a problem with your image being 8-bit but your IM is 16-bit. I use the Q8 version of IM and did conversions using both "-level 94,255" and "-level 37%,100%". They produce the same reasonable looking result. I would have expected that "-level 37%,100%" would give you a correct result because the percent should give the same result with Q8 or Q16.

Pete

Re: Problems with Convert

Posted: 2010-01-16T11:57:04-07:00
by fmw42
In windows, % need to be doubled to %%

Re: Problems with Convert

Posted: 2010-01-16T13:31:44-07:00
by JKEngineer
Thank you both.

I made the change Fred identified, doubling the % to %%. It resulted in the output files matching in both -level 36.9%%,100%% and in -level36.9,100%% and it looks like the locations where the initial value was 94 are now 0, so I guess that the % refers to the % of scale, not a histogram related value. Agreed?

Given that this worked, I don't think the fact that I am using a 16 bit IM version with an 8 bit image should be the problem. I am hesitant to install the 8 bit IM on this machine, for unrelated reasons, but may do so. The 16 bit I am using is, as noted above, portable, so avoids issues with this machine.

Do I have the syntax for convert file -evaluate add x and convert file -evaluate subtract x correct? Do they work? (They don't have an effect for me)

Can the convert -level expression accept pixel values, like 94,255? or only % values? Pete's response seems to indicate success using both approaches. Thoughts? If you come back and say 8 bit vs 16 bit program again, I will install the 8 bit. (Static or dynamic? or does it matter?)

I appreciate your help! And the speed with which you offer it!
Jack

Re: Problems with Convert

Posted: 2010-01-16T15:19:46-07:00
by fmw42
JKEngineer wrote:Thank you both.

I made the change Fred identified, doubling the % to %%. It resulted in the output files matching in both -level 36.9%%,100%% and in -level36.9,100%% and it looks like the locations where the initial value was 94 are now 0, so I guess that the % refers to the % of scale, not a histogram related value. Agreed?

Given that this worked, I don't think the fact that I am using a 16 bit IM version with an 8 bit image should be the problem. I am hesitant to install the 8 bit IM on this machine, for unrelated reasons, but may do so. The 16 bit I am using is, as noted above, portable, so avoids issues with this machine.

Do I have the syntax for convert file -evaluate add x and convert file -evaluate subtract x correct? Do they work? (They don't have an effect for me)

Can the convert -level expression accept pixel values, like 94,255? or only % values? Pete's response seems to indicate success using both approaches. Thoughts? If you come back and say 8 bit vs 16 bit program again, I will install the 8 bit. (Static or dynamic? or does it matter?)

I appreciate your help! And the speed with which you offer it!
Jack
-level uses either raw graylevels in range 0-65535 if using Q16 IM or 0-255 if using Q8 IM or percent graylevels when you add % in range 0-100%. These are not counts. If you want to use counts, then use -contrast-stretch or -linear-stretch. see various discussion of all these methods at http://www.imagemagick.org/Usage/color/

-evaluate add or subtract is the same. so one usually uses percent graylevels in range 0-100%. however, if you want to do add and multiply then see -function polynomial to avoid clipping between -evaluate operations. see http://www.imagemagick.org/Usage/transform/#evaluate

Re: Problems with Convert

Posted: 2010-01-16T15:45:13-07:00
by JKEngineer
Thanks Fred. Looks like Pete called it right also.

The add/subtract values and the level values I used as tests now make sense in terms of the results I got - either no visible change or a white image. I will look at the other commands you mention.

With your and Pete's help, I am making good progress! I appreciate the help. Sorry if these are very basic issues. I did say I was a newbie in my last thread. ;-)

Jack

Re: Problems with Convert

Posted: 2010-01-16T16:10:05-07:00
by fmw42
No problem. We all had to learn at one time or another and I got help from Anthony. So just carrying on the tradition.

Good reading:
http://www.imagemagick.org/script/comma ... ptions.php

And Anthony's extensive examples pages starting at
http://www.imagemagick.org/Usage/
and
http://www.imagemagick.org/Usage/reference.html

Fred

Re: Problems with Convert

Posted: 2010-01-16T20:38:36-07:00
by el_supremo
JKEngineer wrote:Thank you both.
No problemo :-)
so I guess that the % refers to the % of scale, not a histogram related value. Agreed?
Yes.
Given that this worked, I don't think the fact that I am using a 16 bit IM version with an 8 bit image should be the problem.
It is and it isn't.
Can the convert -level expression accept pixel values, like 94,255? or only % values?
Both.
But, when you use IM Q16 to read in an 8-bit image, a value like 94 in the original 8-bit image will be converted to its equivalent 16-bit value internally. So it won't be stored internally as 94 but as 24158 (=65535*94/255). When, for example, you use the -add operator to add 25 to that, it will result internally in 24183. But when that is changed back to an 8-bit quantity to write it in a file it still results in 94. Similarly, a -level of 94 is treated as an absolute value, so in Q16 it is almost black (94/65535) but in Q8 it is fairly bright (94/255).

Pete

Re: Problems with Convert

Posted: 2010-01-16T21:00:39-07:00
by fmw42
Percent means different things in different functions. Most, like -level and -evaluate, etc use percent to be 0% for black and 100% for white. So it is a percent of the graylevel range.

The odd ones are -contrast-stretch and -linear-stretch which use counts. So percent means percent cumulative counts from either end of the histogram.