comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Changing the order of true color images
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Changing the order of true color images [message #28824] Wed, 16 January 2002 05:17 Go to next message
ronn is currently offline  ronn
Messages: 123
Registered: April 1999
Senior Member
in article Z4T08.21077$WQ1.3331811@news6-win.server.ntlworld.com, Martin
Downing at martin.downing@ntlworld.com wrote on 1/15/02 5:01 AM:

> Hi Ronn,
> Flipping an image in Y really is very trivial C code, but maybe if you are
> not used to image data it seems hard. I'll do it for 2d for
> you below, extending to 3d when pixel interleaved will be just a matter of
> setting sx = dim_x*3
>

In the interest of completeness here is the completed C example based on
Martin's suggestion.

/*{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|*/

void flipY( char * image, int ndims, int sx, int sy)
{
int hy,i,j;
char tmp;

hy = sy/2;
if( ndims == 3) sx = sx*ndims;

for (j=0;j<hy;j++) {
for( i=0; i<sx; i++){
tmp = image[i+sx*j];
image[i+sx*j] = image[sx*(sy-j-1)+i];
image[sx*(sy-j-1)+i] = tmp;
}
}
}

/*{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|{{:|*/

-Ronn


--
Ronn Kling
KRS, inc.
email: ronn@rlkling.com
"Application Development with IDL"� programming book updated for IDL5.5!
"Calling C from IDL, Using DLM's to extend your IDL code" NEW BOOK!
http://www.rlkling.com/
Re: Changing the order of true color images [message #28838 is a reply to message #28824] Tue, 15 January 2002 02:01 Go to previous messageGo to next message
Martin Downing is currently offline  Martin Downing
Messages: 136
Registered: September 1998
Senior Member
Hi Ronn,
Flipping an image in Y really is very trivial C code, but maybe if you are
not used to image data it seems hard. I'll do it for 2d for
you below, extending to 3d when pixel interleaved will be just a matter of
setting
sx = dim_x*3

excuse any sytax errors as Im writting this on the fly and am a little rusty
on my C code :), but I'd hope anyone using C could correct it!
ps: Byte == unsigned char

void flipY(Byte *image, int sx, int sy) // image block , x_size, y_size
{
int i,j, hy;
Byte tmp; // temp storage for
hy = sy/2; // halfway though the image

for (j = 0;j <hy;j++) {
for (i = 0;i <sx;i++) {
// SWAP PIXELS [i,j] <=> [i,sy-j]
tmp = image[i+sx*j];
image[i+sx*j]= image[i+sx*(sy-j)]);
image[i+sx*(sy-j)]) = tmp;
} // END FOR I
}// END FOR J

} // END FUNCTION


--
----------------------------------------
Martin Downing,
Clinical Research Physicist,
Grampian Orthopaedic RSA Research Centre,
Woodend Hospital, Aberdeen, AB15 6LS.
m.downing@abdn.ac.uk

"ronn kling" <ronn@rlkling.com> wrote in message
news:B868C3C9.409F%ronn@rlkling.com...
> ?
>>
>> Have you tried the TRANSPOSE function?
>>
>> For example, to change the dimensions from (3, m, n) to (m, n, 3):
>>
>> a = transpose(temporary(a), [1, 2, 0])
>>
> Hi Liam,
>
> I guess I should have been clearer... Right now I can rotate the image
once
> I get it back into IDL, but I would prefer to rotate it on the C side.
Speed
> isn't the issue, having a clean interface for the user is.
>
> I know it is just loops and such, but I was hoping that someone had
already
> solved it.
>
> Thanks,
> Ronn
>
>
> --
> Ronn Kling
> KRS, inc.
> email: ronn@rlkling.com
> "Application Development with IDL" programming book updated for IDL5.5!
> "Calling C from IDL, Using DLM's to extend your IDL code" NEW BOOK!
> http://www.rlkling.com/
>
>
Re: Changing the order of true color images [message #28844 is a reply to message #28838] Mon, 14 January 2002 14:25 Go to previous messageGo to next message
ronn is currently offline  ronn
Messages: 123
Registered: April 1999
Senior Member
?
>
> Have you tried the TRANSPOSE function?
>
> For example, to change the dimensions from (3, m, n) to (m, n, 3):
>
> a = transpose(temporary(a), [1, 2, 0])
>
Hi Liam,

I guess I should have been clearer... Right now I can rotate the image once
I get it back into IDL, but I would prefer to rotate it on the C side. Speed
isn't the issue, having a clean interface for the user is.

I know it is just loops and such, but I was hoping that someone had already
solved it.

Thanks,
Ronn


--
Ronn Kling
KRS, inc.
email: ronn@rlkling.com
"Application Development with IDL"� programming book updated for IDL5.5!
"Calling C from IDL, Using DLM's to extend your IDL code" NEW BOOK!
http://www.rlkling.com/
Re: Changing the order of true color images [message #28849 is a reply to message #28844] Mon, 14 January 2002 07:22 Go to previous messageGo to next message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
ronn kling wrote:
> I am reading in a (very large) pixel interleaved (3,m,n) true color image
> with a C routine. I need to be able to do the equivalent of changing the
> order of the image and I was wondering if anyone has some C code that does
> this?

Have you tried the TRANSPOSE function?

For example, to change the dimensions from (3, m, n) to (m, n, 3):

a = transpose(temporary(a), [1, 2, 0])

Cheers,
Liam.
Practical IDL Programming
http://www.gumley.com
Re: Changing the order of true color images [message #29062 is a reply to message #28849] Mon, 28 January 2002 05:55 Go to previous message
Alex Schuster is currently offline  Alex Schuster
Messages: 124
Registered: February 1997
Senior Member
"Liam E. Gumley" wrote:

> Have you tried the TRANSPOSE function?
>
> For example, to change the dimensions from (3, m, n) to (m, n, 3):
>
> a = transpose(temporary(a), [1, 2, 0])

Just a note: a = transpose( a, [1, 2, 0] ) is the same, the temporary()
function does not save memory when used inside a function.


IDL> a=findgen(1000,1000,10)
IDL> help, /mem
heap memory used: 40206937, max: 40206965, gets: 237,
frees: 96
IDL> a=transpose(temporary(a), [ 1,2,0])
IDL> help, /mem
heap memory used: 40207016, max: 80207156, gets: 242,
frees: 99

IDL> a=findgen(1000,1000,10)
IDL> help, /mem
heap memory used: 40206821, max: 40206849, gets: 231,
frees: 93
IDL> a=transpose(a, [ 1, 2, 0] )
IDL> help, /mem
heap memory used: 40206892, max: 80207040, gets: 236,
frees: 96

Alex
--
Alex Schuster Wonko@planet-interkom.de
alex@pet.mpin-koeln.mpg.de
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Segmentation of Multiple ROIs
Next Topic: Re: problem after upgrading

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:14:24 PDT 2025

Total time taken to generate the page: 0.00676 seconds