08-18-2019 05:37 AM
Reference: OpenCV LinearPolar/WarpPolar
Hello! I would like to ask if there is a LabView-only fast or efficient way of converting a grayscale rectangular image (Integer Array) to a grayscale polar image without resorting to using external libraries. I currently have a Python wrapper to execute the conversion with OpenCV but it would be preferable if there is no external dependencies other than LabView itself.
Solved! Go to Solution.
08-18-2019 02:56 PM
It is not clear what you want to do. What is the nature of your input "Rectangular Image"? I'm guessing that you have a 2D array with N rows and M columns representing X and Y coordinates, and you display them as an NxM pixel display. So what do you mean by a "Polar Image"? I would think it means a 2D array representing Radius and Azimuth angle (rho and theta). The problem is that LabVIEW Images are rectangular arrays of pixels. You can, of course, represent a circle (constant rho, theta varying from 0 to 2 pi) on an XY plot (x = rho cos theta, y = rho sin theta), but this will need to "map" to the integer pixel locations.
Can you provide some more details and explanations? Is this simply an exercise in coordinate transformations (which can be simplified by clever use of LabVIEW Complex conversion functions, see past ingenious Solutions by Christian Altenbach on this Forum)? What am I missing?
Bob Schor
08-18-2019 08:12 PM
It is a coordinate transformation exercise. The intent is to remap an image's pixels from cartesian (X,Y) coordinates to polar (R,θ) coordinates. From the reference in my OP, if I were to have an image of a bunch of vertically parallel lines then it would become concentric circles after the coordinate transform and vice versa. I am aware that there are libraries (such as OpenCV with cvLinearPolar and cvWarpPolar) that can do this though I am curious if there is a way to do this only in LabView.
08-18-2019 09:00 PM
Just use straight up math primitives.
Or look at Real/Imaginary to Polar function. x=Real, y= imaginary. It outputs r and theta!
It is under Numeric >> Complex palette.
08-19-2019 04:13 PM - edited 08-19-2019 04:14 PM
My attempts at remapping the pixels using (rcos(theta),rsin(theta) in LabView seems to tank performance too much that I've resorted to creating a wrapper for OpenCV instead to do the transformation to eliminate the Python dependency. Thank you for the replies!
08-19-2019 04:27 PM
@lukewarmcoffee wrote:
My attempts at remapping the pixels using (rcos(theta),rsin(theta) in LabView seems to tank performance too much...
You are probably doing it wrong. How many pixels do you have and how do you interpolate (nearest? bilinear?)
08-19-2019 04:51 PM - edited 08-19-2019 05:06 PM
Here's a quick test, takes about 70ms* for 1M inputs/outputs (1000x1000 pixels).
(picture shows 128x128, though)
*You can parallelize the outer FOR loop and it drops to ~4ms (for 1000x1000) on my 16(32) core dual Xeon
(Note that this is intentionally simple and does more work than needed. In principle you only need to go radii for the longest diagonal and can thus reduce the points in the r domain, for example)
09-19-2019 07:57 AM
03-10-2020 10:15 AM
Hello,
I tried recreating your VI but the center of rotation isn't correct. My result is the following:
Since I'm quite new to Labview, I'm not sure what I'm going wrong, do you see where I'm making a mistake? Thank you in advance.
03-10-2020 12:47 PM
@MaxPhysics
attach your actual .vi or a snippet not an image
attach your imagedata or save your vi/snippet with "make values default"
this revision is less convoluted: