Discussion:
Scaling a JPEG with ZoomFactor Property
(too old to reply)
tpascaru
2007-02-27 04:10:07 UTC
Permalink
Hello All,
 
I am trying to load a JPEG file and scale it to fit the drawing area of my picture display. I am trying to use the ZoomFactor property, which seems to distort the picture if the scale is less than 1. Interestingly, I found an example in the "examples" folder, and the zoomfactor property seems to work OK there.
 
Is there any magic I have to do in order to get the ZoomFactor to work right?
 
Thanks
-Ted
altenbach
2007-02-27 04:40:12 UTC
Permalink
What do you mean by "distort"? Simply the wrong aspect ratio maybe?
 
Could you show a screenshot of the "distortion"?
What are you doing differently compared to the example code?What is your LabVIEW version?
tst
2007-02-27 11:10:11 UTC
Permalink
I assume you mean something like what is shown in <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=125887#M125887" target="_blank">this thread</a>. LV seems to have some problems when resizing some images.
You can try using the messy example posted <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=215709#M215709" target="_blank">here</a>&nbsp;to resize your image.
tpascaru
2007-02-27 17:10:12 UTC
Permalink
Thanks for the reply folks. At least I somewhat understand it now. I hope NI can fix this in a future release -- every other freeware image viewer has a real time scaling that works well, so it shouldn't be that hard. In the interim, I'll pre-size the JPEG image to the size I want to display. I am enclosing the image since one of the posters requested to see it. It's pretty sad. This is too bad, since I was hoping to implement a help system for finding certain connectors on my printed wiring board. The idea was to zoom in on a photo of a board, and help the user identify the correct component.
&nbsp;
&nbsp;
Regards
-Ted


hermosa butchered.jpg:
http://forums.ni.com/attachments/ni/170/232362/1/hermosa butchered.jpg
tpascaru
2007-02-27 17:40:13 UTC
Permalink
You can still do what you want. Load the full size image and resize it to fit the display using one of the referenced VIs. When the user zooms in, take the original image again and do another resize on it with the new zoom value.

Hi -- I presume you mean that I have to purchase a VI, and I cannot do it with the ZoomFactor property. Is that correct?

Regards

-Ted
tst
2007-02-27 19:10:09 UTC
Permalink
I mean that you can not do this with the zoom property because it doesn't work (note - it might work if you use PNG and not JPG, although I doubt it).
You don't have to buy George's VIs - you can simply follow the link I provided in my first reply which includes a VI which does this and a reference to another VI which does this.
tpascaru
2007-02-27 19:40:11 UTC
Permalink
This post might be inappropriate. Click to display it.
tst
2007-02-27 22:10:08 UTC
Permalink
zou wrote:
tst,
&nbsp;
It seems your zoom.llb doesn't support zoom factor &lt; 1


That's because it was only a very quick proof of concept which was only meant to zoom in. The actual resizing VI supports this, so the slide and the input in the Get Rect VI&nbsp;just needs to be changed to a DBL representation for this to work.
Doug, your VI was not attached.
zou
2007-02-27 23:10:08 UTC
Permalink
tst wrote:



zou wrote:
tst,
&nbsp;
It seems your zoom.llb doesn't support zoom factor &lt; 1


That's because it was only a very quick proof of concept which was only meant to zoom in. The actual resizing VI supports this, so the slide and the input in the Get Rect VI&nbsp;just needs to be changed to a DBL representation for this to work.
Doug, your VI was not attached.


The quality isn't impressive through.
I guess you get what you pay for. ;)
&nbsp;
Doug's VI seems working.
&nbsp;
GeorgeMessage Edited by zou on 02-27-2007 04:53 PM


resize.PNG:
Loading Image...


resize1.PNG:
Loading Image...
tst
2007-02-28 09:10:14 UTC
Permalink
zou wrote:
The quality isn't impressive through.
I guess you get what you pay for. ;)


Can't argue on that. The VI doesn't do any interpolation - it just takes some of the rows and columns (if zooming in)&nbsp;or duplicates some of them (if zooming out).
It usually looks relatively reasonable on images, but in a case like you showed, with straight, thin lines, you sometimes lose some of the information.
I'm not sure about this, but I've seen similar behaviour when Internet Explorer, so it might use a similar algorithm.
Doug M
2007-02-28 14:40:08 UTC
Permalink
Hi everyone,Are we on the same page that scaling seems to be decent in 8.2?&nbsp; I went ahead and did a couple simple tests (disclaimer I know very little about image manipulation).&nbsp; I took the following test image from a <a href="http://www.cinedrome.ch/hometheater/testpatterns/zoneplate.html" target="_blank">website</a> and scaled it in LabVIEW, MS Paint, and The GIMP to 50% to see if there was noticeable image degradation. Message Edited by Doug M on 02-28-2007 08:17 AMMessage Edited by Doug M on 02-28-2007 08:18 AM


scaletest.jpg:
Loading Image...


scaledto50.JPG:
Loading Image...
zou
2007-02-28 16:40:08 UTC
Permalink
Doug M wrote:
&gt;It seems that LabVIEW does as good a job as MS Paint, which obviously isn't a robust image manipulation program.
&nbsp;
With the price we pay for LabVIEW, and IMAQ, we expect the quality comparible to Photoshop, not MS Paint ! ;)
&nbsp;
And it's easy for C++, see what I get
<img src="Loading Image..."> Message Edited by zou on 02-28-2007 10:13 AM


Image Toolbox.png:
http://forums.ni.com/attachments/ni/170/232615/1/Image Toolbox.png
altenbach
2007-02-28 17:40:08 UTC
Permalink
I think we need to balance quality and speed. Somebody might want to display&nbsp;images in quick succession and IF LabVIEW cannot keep up because of scaling issues, people will start complaining even more.
&nbsp;
Sure we all can look at the different algorithms with a magnifying glass, but so far we have NOT looked at the performance impact of a marginally better scaling algorithm. If your LabVIEW program needs to display 10000x10000 images at 20% scale, I am sure the various methods will show a significang difference in speed. Maybe somebody with access to all methods could do a benchmark.
&nbsp;
Ideally, we would like to have a choice in algorithm (optimize for speed, optimize for quality, compromise), so the programmer can decide what is more important for the current situation. Another possibility would be an incremental display: show a quickly scaled image immediately, then, if the image sticks around and there is plenty of idle CPU, improve the quality in the background and redraw a little later (see e.g. Picasa).
&nbsp;
The following image shows three algorithms used by Corel photopaint.

- Resampled at 50% with antialiasing.

- Resampled at 50% without antialiasing

- scaled at 50% in the work area, taken by a screenshot.

As you can see (3) is a compromise for performance reasons. A good reason! :)
<img src="Loading Image..."> Message Edited by altenbach on 02-28-2007 09:14 AM


50PercentVersions.png:
http://forums.ni.com/attachments/ni/170/232632/1/50PercentVersions.png
tpascaru
2007-02-28 18:10:10 UTC
Permalink
All -- thanks for running the tests! I'll be upgrading to 8.2 and, it seems like my needs will be met by the native scaling algorithm. Regarding additional algorithms that trade speed for results, my 2cents is that if Labview wants to get serious about image processing, then, additional algorithms should be available to the user as options. Labview is perfectly suited for this through the property node. Some applications will require speed, others will require performance -- let the user decide.
The resize function in irfanview (the freeware image processing program I use) allows the user to select if they want a resize or a resample, and for the resample option: it has 6 available resampling filters available. (see enclosed photo).
Thanks again to everyone!
-Ted
&nbsp;


iviewResize.jpg:
Loading Image...
tpascaru
2007-02-28 23:10:09 UTC
Permalink
This post might be inappropriate. Click to display it.
tpascaru
2007-03-01 00:10:07 UTC
Permalink
Odd.. here's the sequence of events.

- Open a photo in an image viewer outside of labview

- Copy the photo to the clipboard

- Paste the image onto the front panel of a vi

- Scale the image holding the shift key down (to maintain aspect ratio)

- See the image get munched.

However, if I save the vi with the munched image, and then reopen it -- everything is fine.
-Ted


testvi2.vi:
http://forums.ni.com/attachments/ni/170/232730/1/testvi2.vi


pastedphoto.jpg:
Loading Image...


testvi1.vi:
http://forums.ni.com/attachments/ni/170/232730/3/testvi1.vi
altenbach
2007-03-01 00:10:08 UTC
Permalink
- Just right-click on the full-size test picture above, "right-click..copy" in explorer.

- paste in empty front panel. (as decoration, NO image indicator, etc.)

- grab handle in one corner and resize. (half-size is even uglier!)

(I copied it twice and scaled the top one for that "before&amp;after" effect :))
Here's the 8.20 result:
<img src="Loading Image...">
&nbsp;
Message Edited by altenbach on 02-28-2007 03:52 PMMessage Edited by altenbach on 02-28-2007 03:53 PM


ScalingII.png:
http://forums.ni.com/attachments/ni/170/232731/1/ScalingII.png

tpascaru
2007-02-27 22:40:13 UTC
Permalink
If the community feels the scaling is a problem, I'd like to create a report for R&amp;D on the issue -- the attached VI is my interpretation of what is involved.&nbsp; Could someone post some high rez images of before and after scaling in LabVIEW 8.2 versus some other utility?
Hello -- I'll repost how Labview mucked the image up, as well as the original. Unfortunately, I have not installed LV 8.20, and am still using LV 8.0.1, so I cannot check out your example.
&nbsp;
It would be great if this could get fixed.
&nbsp;
Cheers
-Ted


hermosa butchered.jpg:
http://forums.ni.com/attachments/ni/170/232465/1/hermosa butchered.jpg


hermosa arial.jpg:
http://forums.ni.com/attachments/ni/170/232465/2/hermosa arial.jpg
altenbach
2007-02-27 22:40:13 UTC
Permalink
Hey, I recognice that place! Even found it on Google Earth :)
(See hermosa.png)
&nbsp;
Anyway, looks pretty good in 8.20. Agreed? (nothing fancy, just the property node):
&nbsp;
<img src="Loading Image...">
&nbsp;
&nbsp;
&nbsp;Message Edited by altenbach on 02-27-2007 02:29 PM


halfSize820.png:
http://forums.ni.com/attachments/ni/170/232466/1/halfSize820.png


hermosa.png:
Loading Image...
Loading...