Problems with Convert

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
JKEngineer

Problems with Convert

Post 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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Problems with Convert

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems with Convert

Post by fmw42 »

In windows, % need to be doubled to %%
JKEngineer

Re: Problems with Convert

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

Re: Problems with Convert

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

Re: Problems with Convert

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

Re: Problems with Convert

Post 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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Problems with Convert

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems with Convert

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