LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I scale a picture to fit into a picture indicator?

I have a fixed size picture indicator on my front panel. I load it with different images from file dynamically at run time.

The image files (.jpeg) are acquired over network and the size of the images is not known. I can load the image and determine it's size easy enough, but I want to scale the image to fit into the picture indicator. I don't want to change the size of the indicator, but I want to see the entire image.
0 Kudos
Message 1 of 9
(4,311 Views)
This answer assumes that you are not using the image tools, which are available from NI at extra cost. I have never used them. I have never worked on a project that was willing to buy them for tasks such as yours. I know for certain that those tools will allow you to do what you want to do without too much effort. That being said, let me offer an alternative.

If your images are monochrome you can convert them to pixmap arrays, put them in an Intensity Graph and be done with it. You just have to wire a grayscale colormap to the color table property of the intensity graph. Autoscale the X and Y axes and the image will always fit nicely. I have wanted to do the same thing with color, but no one at NI can tell me how to get the appropriate colormap from my
jpeg for wiring to the color table. As far as I have been able to discern, this approach is not suitable for color images. If you read a jpeg from a file, you can get the colormap, but wiring it to the color table property doesn't yield the desired result.

So I recommend using the function Unflatten Pixmap.vi to get your picture into matrix format. Next you have to decimate the matrix, removing columns and rows to make you image fit. To do this without distortion, you have to remove every other, or every 3rd, or every 4th, etc. in both directions. This limits the size of the resulting image to some whole number ratio relative to the original. If this is not sufficient for your needs, you will have to interpolate rows and columns to get decimation values that are not whole numbers. I'm going to attempt to write a vi to do that. Let me know if you want it and I'll send it to you when I am done. I have done the decimation part and it works very well. I am certain the interpol
ation will work, too.
jc
Mac 10.4
LV7.1
CLD
Message 2 of 9
(4,311 Views)
I'm still certain that interpolation will work, but I'm not sure how to do it. I got an irregular decimation to work just fine. To get the decimation to work, we need to know more about the image structure. There must be some mosaicing or something like that in an 8-bit color image, because straightforward linear interpolation doesn't work.
jc
Mac 10.4
LV7.1
CLD
0 Kudos
Message 3 of 9
(4,311 Views)
I just noticed a typo. I meant to say, "To get the interpolation to work, we need to know more about the image structure."
jc
Mac 10.4
LV7.1
CLD
0 Kudos
Message 4 of 9
(4,311 Views)
Hi jcrooke,

I have not done this myself so my comments may be of little use but here goes.

Re: down sizing an image.
The value of multiple pixels need to be combined into a single pixel. When downsizing in two dimensions, a rectangle of pixels must be mapped to a pixel. I would think that the RGB values of each of the pixels in the original rectangle could be averaged and the three color components re-assembled to get the color of the final pixel.

I also belive that this can be taken a step farther by using weighting techniques to allow the "center" (assuming odd number dimensioned rectangles) pixel to have a greter influence on the color that the surrounding pixels. I would think that a logrithmic or gausian weighting would proba
bly give good results.

Well, that the extent of my thoughts.

Anyone who really knows what they are talking about are welcome to jump on these ideas.

I would be interested in seeing any code that does this.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 9
(4,311 Views)
Thanks for your time, Ben, but the particular image that I am downsizing in my example is an 8-bit color pixmap, not a true color (RGB) pixmap. Each pixel (matrix element) contains an integer from 0 to 255. I'm not sure how the color information is stored in this type of matrix, but I highly doubt that it is all contained in a single pixel. I'm guessing that there is a stippling technique of some type applied to this image and that the different colors are stored in different pixels. Whatever the format may be, the draw flattened pixmap vi seems to know how to handle it. If the pixels were 24-bit (or 32 bit) values containing all three colors, I agree that it would be necessary to interpolate the colors individually.

I th
ink a simple interpolation should work; although, a more complicated filter as you have suggested would provide a higher fidelity image.
jc
Mac 10.4
LV7.1
CLD
0 Kudos
Message 6 of 9
(4,311 Views)
My "Image Resize.vi" can change the size for you.

http://www.geocities.com/gzou999/resize.htm
http://www.geocities.com/gzou999/imgtool.htm


George Zou
George Zou
0 Kudos
Message 7 of 9
(4,311 Views)
1)Does it cost money?
2)The resize function stipulates that a 24-bit color image, i.e. RGB true color, must be used. What happens if the image is an 8-bit color image?
jc
Mac 10.4
LV7.1
CLD
0 Kudos
Message 8 of 9
(4,311 Views)
If you have WinXP, you can use the XP version of that VI (high quality for all color depth). Otherwise, there is a VI in the package to convert 8 bit to 24 bit. However after resize, you can't convert the image back to 8 bit, otherwise you'll lose high quality, but still butter than a low quality algorithm.

The VI uses Microsoft algorithm. Image quality compatible with other commercial software. There are a lot of other good features in the package. It's cost $29.99

George Zou
http://gtoolbox.yeah.net
George Zou
0 Kudos
Message 9 of 9
(4,311 Views)