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

Home » Public Forums » archive » Is it possible to rotate a flipped image with cgImage?
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
Is it possible to rotate a flipped image with cgImage? [message #88842] Wed, 25 June 2014 04:56 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello,

I have a .JPG image, which requires flipping over the top-down axis before rotating the image by 60 degrees ( clockwise counting ).

I now read the JPG image file as below and place:

READ_JPEG,ImgFile.JPG,img,/ORDER
; Flipping the image
flipHorImg = REVERSE(img,1)
; Rotate the flipped image by 60 deg clockwise direction
rotImg = ROT(flipHorImg,60,0.8,/INTERP)
cgImage,rotImg,Position=pos2,/OVERPLOT

I get an error like this ...
% POLY_2D: Expression must be an array in this context: I.

I don't see a problem with flipping of the image, but there is actually a problem with rotated image. While I know that with cgImage, I can use the keyword /NEGATIVE for flipping the image but there is no option for rotating the flipped image. Anyone with a solution and an example will be of great help.
Re: Is it possible to rotate a flipped image with cgImage? [message #88844 is a reply to message #88842] Wed, 25 June 2014 05:45 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
> I get an error like this ...
>
> % POLY_2D: Expression must be an array in this context: I.

The documentation says, "The image array to be rotated. This array can be of any type, but must have two dimensions."

You can try separating the color channels and rotating them individually (below). Or you could try to convert the rgb values to color table indices.

IDL> im = cgdemodata(16)
IDL> help, im
IM BYTE = Array[3, 227, 149]
IDL> r = reform(flipIm[0,*,*])
IDL> g = reform(flipIm[1,*,*])
IDL> b = reform(flipIm[2,*,*])
IDL> rrot = rot(r, 60, 0.8, /INTERP)
IDL> brot = rot(b, 60, 0.8, /INTERP)
IDL> grot = rot(g, 60, 0.8, /INTERP)
IDL> rotflipIm = transpose([[[rrot]], [[grot]], [[brot]]], [2, 0, 1])
IDL> help, rotflipim
ROTFLIPIM BYTE = Array[3, 227, 149]
IDL> cgimage, rotflipim
Re: Is it possible to rotate a flipped image with cgImage? [message #88847 is a reply to message #88844] Wed, 25 June 2014 06:14 Go to previous messageGo to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello Matthew,

Thanks for the example. If I see the images of im and (flipIm or rotflipIm), then there the rose color is changed to blue. I don't want to change the colors from my original image. I wanted to have my original image with all colors as they are and then only apply this flipping and rotation.

Without using interpolation, can't I retain my image as it is and enclose in the available space? I mean if the original image is a square type, the final rotflipIm can be rhombus type. Is this not possible? In order to fill the missing pixels of the im images, can't we use missing color as white?

Look's the image rotation is distorting the original image completely.

Thanks in advance,
Madhavan



On Wednesday, June 25, 2014 2:45:02 PM UTC+2, Matthew Argall wrote:
>> I get an error like this ...
>
>>
>
>> % POLY_2D: Expression must be an array in this context: I.
>
>
>
> The documentation says, "The image array to be rotated. This array can be of any type, but must have two dimensions."
>
>
>
> You can try separating the color channels and rotating them individually (below). Or you could try to convert the rgb values to color table indices.
>
>
>
> IDL> im = cgdemodata(16)
>
> IDL> help, im
>
> IM BYTE = Array[3, 227, 149]
>
> IDL> r = reform(flipIm[0,*,*])
>
> IDL> g = reform(flipIm[1,*,*])
>
> IDL> b = reform(flipIm[2,*,*])
>
> IDL> rrot = rot(r, 60, 0.8, /INTERP)
>
> IDL> brot = rot(b, 60, 0.8, /INTERP)
>
> IDL> grot = rot(g, 60, 0.8, /INTERP)
>
> IDL> rotflipIm = transpose([[[rrot]], [[grot]], [[brot]]], [2, 0, 1])
>
> IDL> help, rotflipim
>
> ROTFLIPIM BYTE = Array[3, 227, 149]
>
> IDL> cgimage, rotflipim
Re: Is it possible to rotate a flipped image with cgImage? [message #88849 is a reply to message #88847] Wed, 25 June 2014 07:00 Go to previous messageGo to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den onsdagen den 25:e juni 2014 kl. 15:14:47 UTC+2 skrev Madhavan Bomidi:
> Hello Matthew,
>
> Thanks for the example. If I see the images of im and (flipIm or rotflipIm), then there the rose color is changed to blue. I don't want to change the colors from my original image. I wanted to have my original image with all colors as they are and then only apply this flipping and rotation.
>
> Without using interpolation, can't I retain my image as it is and enclose in the available space? I mean if the original image is a square type, the final rotflipIm can be rhombus type. Is this not possible? In order to fill the missing pixels of the im images, can't we use missing color as white?
>
> Look's the image rotation is distorting the original image completely.
>
> Thanks in advance,
>
> Madhavan
>

The reverse command does not know anything about images, it only knows about arrays. And the first dimension of the rose image array is the RGB dimension (of length 3). If you reverse that, in effect you swap the red and blue channels.

If you want to flip it in any of the spatial directions, you should do reverse(im,2) or reverse(im,3), not reverse(im,1).
Re: Is it possible to rotate a flipped image with cgImage? [message #88850 is a reply to message #88847] Wed, 25 June 2014 07:11 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
As Mats pointed out, I forgot one line before...

IDL> flipIm = reverse(im, 2)

The following requires a 2D image, but it will do what you want. For 3D images, it would probably be easiest to use the Image() function.

cgLoadCT, 13
cgshade_surf, bytarr(227,149), indgen(227), indgen(149), SHADES=bytscl(dist(227,149)), ROTZ=60, ROTX=90, XSTYLE=5, YSTYLE=5, ZSTYLE=5
Re: Is it possible to rotate a flipped image with cgImage? [message #88853 is a reply to message #88842] Wed, 25 June 2014 09:58 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

>
> I have a .JPG image, which requires flipping over the top-down axis before rotating the image by 60 degrees ( clockwise counting ).
>
> I now read the JPG image file as below and place:
>
> READ_JPEG,ImgFile.JPG,img,/ORDER
> ; Flipping the image
> flipHorImg = REVERSE(img,1)
> ; Rotate the flipped image by 60 deg clockwise direction
> rotImg = ROT(flipHorImg,60,0.8,/INTERP)
> cgImage,rotImg,Position=pos2,/OVERPLOT
>
> I get an error like this ...
> % POLY_2D: Expression must be an array in this context: I.
>
> I don't see a problem with flipping of the image, but there is actually a problem with rotated image. While I know that with cgImage, I can use the keyword /NEGATIVE for flipping the image but there is no option for rotating the flipped image. Anyone with a solution and an example will be of great help.

I would do it like this:

filename = Filepath(SubDir=["examples","data"], "marsglobe.jpg")
imageOrig = Read_Image(filename)
image = Transpose(imageOrig,[1,2,0]) ; For ease of handling
image = Reverse(image,2) ; Reverse in Y direction
r = Rot(image[*,*,0], 60, 0.9, Missing=255)
g = Rot(image[*,*,1], 60, 0.9, Missing=255)
b = Rot(image[*,*,2], 60, 0.9, Missing=255)
rotImage = [[[r]],[[g]],[[b]]]
cgDisplay, 900, 300
!P.Multi = [0,3,1]
cgImage, imageOrig
cgImage, image
cgImage, rotImage
!P.Multi=0
END

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: Is it possible to rotate a flipped image with cgImage? [message #88856 is a reply to message #88853] Thu, 26 June 2014 09:39 Go to previous message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Thanks to Mats, Matthew and David. I did in a different manner now using SPAWN tool.

SPAWN, 'convert '+image.JPG+' -flop -rotate +60 '+imageFlopRotate.JPG

This works fine in my IDL code!!!

Regards,
Madhavan
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Output matrix from Wavelet Toolkit 3D Wavelet Power Spectrum
Next Topic: A case for lookarounds in StRegEx()

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

Current Time: Wed Oct 08 11:45:12 PDT 2025

Total time taken to generate the page: 0.00507 seconds