Convert raw image: size problem

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?".
aboys

Convert raw image: size problem

Post by aboys »

Hello there,

I am a new guy to use Linux system and this IM.

I have a question about command "convert -size" for converting raw image.

Here it is:

So far as I know, convert -size value needs specific numbers for the size, and it works of course.
Now I would like to convert many raw images with different sizes in a loop, so i did like this:

uUe an array size(2) for the width and height, so the command is convert ... -size $size[1]x$size[2] ...
But it gave me an error message that "Must specify image size", I checked but still dont know how to do.

Can anyone help me ?

Thanks in advance!

PS: I worked for version 5.*, but failed for 6.*
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert raw image: size problem

Post by fmw42 »

arrays in (bash) unix start with index 0

and are referenced as

-size ${size[0]}x${size[1]}

the braces are important. For more information on arrays in unix, search google for "bash array"

Strongly urge you to upgrade to the latest IM 6.6.0-5. IM 5 is very old. Many improvements have been made since then.

Also see

http://www.imagemagick.org/Usage/

and in particular http://www.imagemagick.org/Usage/basics/#why
aboys

Re: Convert raw image: size problem

Post by aboys »

Thank you very much for your quick reply, fmw42.

I use Cshell and when using echo ''${size[1]}x${size[2]} '', it can give right answer.

So maybe it is not that problem.

And I changed ''$size[1]x$size[2]'' to ''${size[1]}x${size[2]} '', still have the same problem.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert raw image: size problem

Post by fmw42 »

What is your exact command?

Did you specify RGB:inputimage.raw i.e. the prefix RGB:

Where are you getting the raw image?

Do you have the correct delegate library installed for reading raw images. In Windows, it is DCRAW, but I am not sure I know what it is for Unix.
Last edited by fmw42 on 2010-03-14T00:04:12-07:00, edited 1 time in total.
aboys

Re: Convert raw image: size problem

Post by aboys »

Ok, here is my exact command:

convert -depth 8 -normalize -quality 100 -colorspace gray -geometry 15% -size $size2[1]x$size2[2] gray:$cwd/$image1 $outimage.png

Just now I read the website you gave to me and found that maybe the problem of the order of the parameters.

The raw images are the satellite data.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert raw image: size problem

Post by fmw42 »

I am not sure -geometry 15% is valid in this context. It is used when doing composites. I think you want -resize.

for IM 6 try

convert -colorspace gray -size $size2[1]x$size2[2] gray:$cwd/$image1 -resize 15% -normalize -depth 8 -quality 100 $outimage.png
aboys

Re: Convert raw image: size problem

Post by aboys »

Sorry, still not working.

The value of "${size[1]}x${size[2]}" can not be passed to the convert command.

This is the problem.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert raw image: size problem

Post by fmw42 »

try using simple variables instead of array elements. put width in one variable and height in another

in bash

width=500
height=500
convert -size ${width}x${height} ....

in bash shell, I know this works as well as using arrays such as ${size[0]}x${size[1]} where the index of the array starts at 0. I don't use the C shell, so cannot say how to use arrays there with IM.

Have you verified that you are getting the right values in your arrays. Try echo the values back to the shell to see they are correct.

Also just try hard coding the sizes

convert -size 500x500 ...

and see if that works correctly.
aboys

Re: Convert raw image: size problem

Post by aboys »

Hi, fmw42,

Sorry for not posting the problem completely.

I tried the "-size 300x400" before and it works, but the "-size ${size[1]}${size[2]}" does not work for IM v6 but works for IM v5.

because i dont know much about unix and cshell, i can not find out the reason...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert raw image: size problem

Post by fmw42 »

-size ${size[1]}${size[2]}

did you mean

-size ${size[1]}x${size[2]}

or have you forgotten to include the x?

Can you try with normal variables rather than an array? Why do you need the array?

Can you switch to the bash shell?

Did you echo your array elements to verify that they contain the right values?
aboys

Re: Convert raw image: size problem

Post by aboys »

Sorry, my fault, it is -size ${size[1]}x${size[2]}.

I echoed the array elements and they were right.

because I need to process many raw images, and their sizes are different so I can not just give two constants for the size.

I am not sure if I can shift to b shell, but i wonder if it is the problem of C shell, because I can get correct results from IM v5 with the same program under C shell.
Last edited by aboys on 2010-03-14T00:39:47-07:00, edited 1 time in total.
aboys

Re: Convert raw image: size problem

Post by aboys »

Sorry, my fault, it is -size ${size[1]}x${size[2]}.

I echoed the array elements and they were right.

because I need to process many raw images, and their sizes are different so I can not just give two constants for the size.

I am not sure if I can shift to b shell, but i wonder if it is the problem of C shell, because I can get correct results from IM v5 with the same program under C shell.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert raw image: size problem

Post by fmw42 »

but can you not change the two variables for each image, just like you change the elements of the array?

or set two variable to be set equal to the two array elements and then reference the variables in the -size arguments

width=$size[1]
height=$size[2]

convert -size ${width}x${height} ....



does it work with

-size $size[1]x$size[2]
aboys

Re: Convert raw image: size problem

Post by aboys »

Ok, I can try that.

-size $size[1]x$size[2] also works.


Well, thank you very much, fmw42, for your helpful, kind and quick reply.

I am not sure if it works after changing the settings, but i should not waste your time any more.

Maybe i ignored some points which i never know before, so i would like to check it in details again.

Hope I can find something.


Thank you very much again for your help. :D
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert raw image: size problem

Post by fmw42 »

OK. I am out of ideas for the moment and time for bed anyway. So I will check again tomorrow and let you know if I have any further thoughts or if you find other issues, let me know.
Post Reply