Re: cgimage [message #81118 is a reply to message #79568] |
Wed, 15 August 2012 12:51   |
DavidF[1]
Messages: 94 Registered: April 2012
|
Member |
|
|
Gompie writes:
> When I set yrange=[a,b] in cgplot it plots values between a,b. How is is possible to do the same in cgimage.?
Interestingly, I had the occasion this morning to want something very much like this. I have two images, one larger than the other, but both only having image data in part of the rectangular array. The images are in GeoTiff files, so I can find the projected ranges of the image rectangles.
It turns out there is imperfect overlap between the valid data in the two images, so I wish to create a single image that shows only the overlapping data. So, the idea is this, fit a smaller image onto the larger, and do it in such a way that you clip any part of the smaller image's valid data that is not also part of the larger image's valid data.
Essentially, I have to clip the smaller image based on its "axis" values.
My code looked like this. "Zone" is a zonal map and "land" is a LandSat image.
The ranges are in projected meter space.
zone = 'quer_zones_ext.tif'
land = 'L5224069_06919980623_B50.TIF'
mzone = cggeomap(zone, image=image)
mzone -> Getproperty, XRange=zxr, YRANGE=zyr
cgdisplay, Aspect=image, xsize=800
cgLoadct, 33, ncolors=6, bottom=1
cgImage, image, XRange=zxr, YRANGE=zyr, /save
mland = cggeomap(land, image=img)
mland ->GetProperty, XRange=lxr, YRange=lyr
x0 = zxr[0] > lxr[0]
x1 = zxr[1] < lxr[1]
y0 = zyr[0] > lyr[0]
y1 = zyr[1] < lyr[1]
xr = [x0,x1]
yr = [y0,y1]
s = Size(img, /DIMENSIONS)
xvec = Scale_Vector(Findgen(s[0]), lxr[0], lxr[1])
yvec = Scale_Vector(Findgen(s[1]), lyr[0], lyr[1])
xsubs = Value_Locate(xvec, xr)
ysubs = Value_Locate(yvec, yr)
imgsub = img[xsubs[0]:xsubs[1], ysubs[0]:ysubs[1]]
To display the clipped, smaller image on the first, I made a slight modification to cgImage, which I will check in later today. Basically, if you set the OVERPLOT keyword *and* you specify both an XRANGE and YRANGE when you call cgImage, I will adjust the image position in the window to place the image at the proper location in the set of axes that are currently defined for the window.
Cheers,
David
|
|
|