LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Image/Picture to to 2d Array Without Using PictureToPixmap


@re-fuse wrote:

... (with filled interior) ...

 


What defines the "interior"? can you show a sketch of the final image? Do you just want the lines to be wider than 1 pixel?


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 11 of 22
(804 Views)

Or are you just talking about line interpolation between defined points? That seems trivial.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 12 of 22
(796 Views)

@altenbach wrote:

Or are you just talking about line interpolation between defined points? That seems trivial.


Here's one possible solution for that. Modify as needed.

(this is just a quick a dirty draft. I am sure it can be improved).

 

Of course you would need to include the correct scaling between values and indices. My algorithm should be applied once the data is quantized to pixels.

 

 


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 13 of 22
(785 Views)

Once you have a continuous outline, a flood fill is simple If you can make certain assumptions about the shape. Is that what you want?

 


LabVIEW Champion Do more with less code and in less time
Message 14 of 22
(771 Views)

@altenbach wrote:

What defines the "interior"? can you show a sketch of the final image? Do you just want the lines to be wider than 1 pixel?

your last post is exactly what i want.


in this sketch you can see the shape before and after filling it.


sketch.png

 

later on i used the point coordinates from the filled shape to draw the picture.

how exactly did you do the flood fill? without using picture functions i assume.

0 Kudos
Message 15 of 22
(753 Views)

@re-fuse wrote:
how exactly did you do the flood fill?

There are plenty of flood fill algorithms discussed on the web (start here) but they require a definition of what is "inside" and "outside"  In your case, the array border seems to be outside and you have two independent areas to fill. Is this always the case? You only have one array of points. How do you know when one curve ends and the other starts to prevent connecting them? The XY data in the VI you attached earlier is rather boring (just a rectangle), so it wouold be nice to have something with a bit more realistic data. Is the data always symmetric? Would it be sufficient to define the upper curve and just mirror it for the lower half?

 


re-fuse wrote: 

later on i used the point coordinates from the filled shape to draw the picture.


At the end you transform the 2D array into a picture. No need for coordinates and no drawing involved.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 16 of 22
(741 Views)

altenbach wrote:

There are plenty of flood fill algorithms discussed on the web (start here) but they require a definition of what is "inside" and "outside"  In your case, the array border seems to be outside and you have two independent areas to fill. Is this always the case?

i've tried those floodfill algorithm (this one) but i weren't successful. the 1d array of point coordinates define the border of my shape and what's inside and outside.

the problem is that the number of shapes (respectively the number of independent areas to fill) is not always the same ... in the example above i have to 2 shapes but sometimes it's just one (e.g. rectangle), sometimes many more.

that's why the floodfill algorithm didnt work cause i'd have to manually define where's inside/outside for each shape.

 

altenbach wrote:

How do you know when one curve ends and the other starts to prevent connecting them? The XY data in the VI you attached earlier is rather boring (just a rectangle), so it wouold be nice to have something with a bit more realistic data. Is the data always symmetric? Would it be sufficient to define the upper curve and just mirror it for the lower half?

each shape is defined by a cubic bezier curves. in that beam-splitter example above i have 24x bezier curve, 12x for the upper arm and 1x for the lower arm ... and the last bezier curve ends where the first bezier curve starts so that the shape is complete.

i than transform every cubic bezier curve into 1d array of points using the De Casteljau's algorithm.

unfortunately the data/shape is not always symmetric ... so mirroring is no solution here.

 

i've attached a VI with more realistic data.

0 Kudos
Message 17 of 22
(723 Views)

@re-fuse wrote:

 

that's why the floodfill algorithm didnt work cause i'd have to manually define where's inside/outside for each shape.

 


I thought that you know that the array edge is "outside", thus you can easily find all the "inside" areas. i.e. all pixels where you cross a border an odd number of times. OTOH, the outside seems to be contiguous, so why not anti-fill the ouside instead? (Start with an U8 array of ones, interpolate the edges and fill with twos, then fill the outside with zeroes. change to boolean array using "not equal zero" or similar).

 


@re-fuse wrote:

 

each shape is defined by a cubic bezier curves. in that beam-splitter example above i have 24x bezier curve, 12x for the upper arm and 1x for the lower arm ... and the last bezier curve ends where the first bezier curve starts so that the shape is complete.

 


You still need to define where one curve ends and the next curve starts, else my algorithm would connect the last point of one area with the first point of the next area and you get one extra line. that messes up the fill algorithm. I don't understand how your numbers add up (24x, 12x, 1x). How many points per curve are there?

 

 

 


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 18 of 22
(715 Views)

@re-fuse wrote:

 

i've attached a VI with more realistic data.


The VI does not contain any data. You need to make the values default before saving and attaching. (Or just right-click the terminal of the control (once it contains the data!) and "create constant". Now delete everything but that constant, save VI under a new name and attach it here.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 19 of 22
(713 Views)

altenbach wrote:

I thought that you know that the array edge is "outside", thus you can easily find all the "inside" areas. i.e. all pixels where you cross a border an odd number of times. OTOH, the outside seems to be contiguous, so why not anti-fill the ouside instead? (Start with an U8 array of ones, interpolate the edges and fill with twos, then fill the outside with zeroes. change to boolean array using "not equal zero" or similar).

well i know the inside&outside of each shape cause it is defined by the array edge.
for the floodfill algorithm i'd have to define a starting point and i've always used a point inside the shape ... this way there are of course as many starting points as there are shapes. i've never got the idea to anti-fill the outside cause the outside is always contigous .. silly me!

 

You still need to define where one curve ends and the next curve starts, else my algorithm would connect the last point of one area with the first point of the next area and you get one extra line. that messes up the fill algorithm. I don't understand how your numbers add up (24x, 12x, 1x). How many points per curve are there?

iam sorry ... i should have explained in more details.

the number of bezier curves that define the whole shape depends on the complexity of the shape.
for example a rectangle consist of 4 lines so you would need 4 bezier curves ... and each bezier curve starts (respectively ends) where the previous curve ends (respectively where the next curve starts).

in case of the beam-splitter shape each arm (upper & lower) is defined by 12 bezier curves. so for the whole beam-splitter i've got 24 bezier curves defining the shape.

the number of points depends on how fine i want each bezier curve to be approximated by equidistant points (de casteljau algorithm).

 

i've tried your interpolating algorithm ... but it didnt work and i honestly dont know why.

 

i've attached the current VI. this time with data.

you can see the defining points of each bezier curve and the calculated points based on de casteljau algorithm.

sorry for the empty VI last time .. i've forgot to make all values default.

 

0 Kudos
Message 20 of 22
(693 Views)