Correct Image Resizing -- New Coyote Program [message #73699] |
Sat, 20 November 2010 12:52 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Folks,
TVImage was first written--can you believe this!--nearly
15 years ago. In those 15 years, I think I can count on
one hand the number of times I've used a TV command in
an IDL program.
In the past week or so, I have been updating this program
to work more seamlessly with a new series of Coyote Library
programs that are meant to bring New Graphics like functionality
to all versions of IDL (FSC_Contour, FSC_Plot, etc.).
When I wrote the program there were problems with Congrid
not interpolating from the center of a pixel, but from its
lower-left corner. This was (and is) a problem for astronomers
because if the pixel wasn't centered, the pixel "location" would
change slightly. This is almost unnoticeable with large images,
but can be a factor when you don't have very many pixels to work
with.
This deficiency has since been corrected by a CENTER keyword
to the Congrid command. At the time I wrote TVImage, I resized
the image with the program CM_CONGRID, written by Craig
Markwardt. It used a HALF_HALF keyword to perform the pixel
centering.
I thought about just switching to Congrid for image resizing,
but Congrid has another problem when resizing images. Congrid
is not able to recognize the difference between a 3D array, and
a true-color image, in which one of the dimensions is a 3. As
a result, this "3" dimension is interpolated in the same manner
as the other two dimensions. It should not be. If the dimension
is interpolated, small differences in pixel color can occur.
Again, this is something that is not particularly noticeable,
unless you are an astronomer working with relatively few pixels,
where color can be extremely important.
Congrid has one further weakness. It always interpolates 3D images
with bilinear interpolation. Astronomers, I have discovered, HATE
interpolated pixels! The old CM_CONGRID program was able to
use nearest neighbor resampling even for 3D images.
All this background to say that I have written a new program,
FSC_Resize_Image, that is ONLY for 2D and true-color images,
and that combines the best of Congrid and CM_Congrid to provide
a consistent (and I think, correct) interpolation or resizing
of images.
2D images are passed directly to Congrid, but with the CENTER
keyword set to 1, and with a default MINUS_ONE keyword set to
1, too. (Setting the MINUS_ONE keyword insures that Congrid
doesn't extrapolate an extra column or row beyond the bounds
of the input image.)
3D or true-color images are handled in a manner that is
consistent with the CENTER keyword being set to 1, except
that the "3" dimension of the image is not interpolated
to avoid color shifts in the image, and nearest neighbor
resampling is available. The INTERPOLATE keyword determines
the interpolation method, as it always has. (This keyword
is ignored for 3D images in Congrid.)
You can find the new image resizing program here:
http://www.dfanning.com/programs/fsc_resize_image.pro
I have updated TVImage and TVScale to take advantage of
this new method for image resizing. If you haven't updated
these two commands in awhile, you might want to do so. There
have been a LOT of new features added recently.
http://www.dfanning.com/programs/tvimage.pro
http://www.dfanning.com/programs/tvscale.pro
As always, feedback is appreciated. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|