Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

how to do parallel image rotation in for loop?

Solved!
Go to solution

Dear All,

 

I try to using parallel For Loop to rotate an image 180 times, but the cost time was the same as without using parallel For Loop.

Any one knows the reason?

The parallel For Loop looks as below.

parallelforloop

0 Kudos
Message 1 of 9
(5,445 Views)

Seems the input is a imaq reference, which unlike an array, can't be copied. Right?

0 Kudos
Message 2 of 9
(5,431 Views)

Correct, the IMAQ image data type is just a reference to the memory location, which does not have any advantage in parallel. You could always turn the IMAQ image into an array to use data manipulation directly, but this would slow other functions by constantly passing large arrays through the VI.

0 Kudos
Message 3 of 9
(5,412 Views)
The image type has knowledge of operations that read versus write the image. The source image being rotated can be read in parallel by multiple threads. However, your dest image requires write access and so each parallel loop must acquire an exclusive lock to that image, making it serialized.
0 Kudos
Message 4 of 9
(5,406 Views)

Sorry, Epsilon, that won't work.  You are autoindexing on an array with 8 elements.  The second loop will only loop 8 times instead of the desired 180 times.  It would work if you created 180 images for the destination.  I'm not sure how to write it so the parallel loops will each use a different destination image.  Maybe two nested loops?

 

This loop is rather pointless, anyway, since the results are overwritten on each iteration.  I assume there are more operations following the rotation in the full code, and each rotation is a different angle.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 6 of 9
(5,396 Views)

Thanks for all repliers. You all help me a lot.

 

I did like this below

It produces 180 images from 0-179 degrees, and is 3.5 times faster than without parallel processing.

The interesting thing is the output images array from the 2nd for loop are in the right rotation order, from seeing Image 2.

I thought they would be in the wrong orders or radom orders.

Any explanations?

T2.jpg

0 Kudos
Message 7 of 9
(5,391 Views)

I suppose the parallel processing could be a faster implementation for some algorithm, such as radon transform, hough transform, or find lines in an image, of course not as faster as GPU based processing. 

0 Kudos
Message 8 of 9
(5,389 Views)

The array is in the correct order because parallel processings breaks the array apart but puts the results back together in the same order.  It is designed so the output looks exactly the same as the non-parallel version.

 

I would eliminate the display during rotation.  That is probably slowing things down a bit, and it doesn't make much sense when the loop is in parallel.  The order of the images displayed within the parallel loop will be all mixed up.  Also, you could eliminate the integer arrays and just wire i to the angle input, but I suspect that one is obvious.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 9 of 9
(5,369 Views)