From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Vision: Draw instead of overlaying rotated shapes

Hi all,

 

in my applications I frequently deal with quite large images, 90 Megapixels or larger. We have to do defect detection on those images. Once we found them we mark the positions using coloured overlays. Because of the "Overlay ROI" function I am able to overlay rotated rectangles. For visualising this is all quite well. However when having to save this information to an image file I get a bit of a problem: Merging the overlays quadruples/triples the amount of memory taken up in RAM and on harddisk, as the IMAQ reference for the merged picture has to be of type color U32 instead of my U8 greyscale (and on disk will be 24bit PNG/BMP instead of 8Bit).

 

In order to keep the memory figures on a normal level I started to use an extra IMAQ reference of type U8 greyscale where I draw all the shapes using the IMAQ Draw functions. Then I add the number of different colors of drawn overlays to the image pixel values which leaves me free to define a user palette where the first n entries are the colors of the different overlays and the rest remains greyscale (unnoticebly increasing the brightness of the U8 image). Then I save the image as U8 using the user defined palette. So far so good. What stumps me here is that there seems to be no native "LabVIEW"-way to draw a rotated rectangle or oval.

 

I have come up with a couple approaches to tackle this problem, but maybe I am missing a great built-in function here:

  1. first create the merged image, threshold it for the various colors thus producing the desired shapes as binary and then somehow fiddle the original U8 and the binarized "overlay" information together. This is kind of using cannons on sparrows, as we say in Germany...
  2. Extract the original ROI information to create 4 angled lines instead of one rotated rectangle and then draw these lines forming  the rotated rectangle. This seems mainly straight forward, however the ROI type 12 (rotated rectangle) doesn't change its coordinates in Contour just because it gets rotated. So would have to do some trig to determine those 4 lines I need.

I would appreciate any hint if there's an easier way to do what I want to accomplish

 

0 Kudos
Message 1 of 7
(3,713 Views)

Hi Comrade,

 

i find it pretty hard to understand what you are doing. Could you please provide some pictures for a better understanding?

0 Kudos
Message 2 of 7
(3,686 Views)

Sorry, I seem to have overloaded you with information. The question is actually quite a simple one:

 

Is there an easy, ready-made way to DRAW (NOT overlay!) a rotated rectangle to an image other than:

  1. merge the overlay (this takes too much time and memory during processing and saving the image)
  2. emulate the rotated rectangle overlay by drawing individual lines (this is somewhat cumbersome as there is some calculation to be done to get those line coordinates from the ROI describing the rotated rectangle) ?

I'll think on how to illustrate that, but actually this is not about visualisation but about performance (concerning processing time) and memory usage.

0 Kudos
Message 3 of 7
(3,680 Views)

Hi, Comrade,

 

are you working with the vision assistant or with the vis? This is just a shot in the dark but maybe you could check this vi:

 

Draw Text in an Image - National Instruments
http://www.ni.com/example/26905/en/

Message 4 of 7
(3,672 Views)

Well, of course, IMAQ Draw functions are neat. But as I pointed out in my initial post - they do not support the drawing of a rotated rectangle.

 

Please find in the attachment a VI and a simple test image. This resulting image after running the VI shows what I receive using the overlaying technique. The question is: What is the simplest way (in terms of coding AND performance) to turn those overlay shapes into pixel coordinates that I can use to draw these shapes into an image.

 

The final goal here is to reduce the amount of harddisk space used up by saved result images via applying a user defined color table to a U8 image as opposed to just savig a color image with all the overlays merged, as described above in the initial post.

Download All
0 Kudos
Message 5 of 7
(3,661 Views)

Why don't you create the Overlays, merge them with the image and re-convert the image back to 8-bit for saving.....? Seems like the easiest way to do things.  You'll only have the 32-bit image briefly in memory.

 

Shane

Message 6 of 7
(3,639 Views)

Sounds a bit like my proposal 1 in the initial post. When testing it proved easier to code than I originally thought it would be. I came up with the attached VI (added the necessary parts to the one I posted earlier. Maybe there's an easier way but thanks anyway Intaris!

0 Kudos
Message 7 of 7
(3,617 Views)