LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing on through case structures

In my program I am calculating pixel values for a binary spatial light modulator. Each time I calculate a value, this value is rounded to either a 0 or a 1. This rounding induces an error that is weighed and then diffused to surrounding unprocessed pixels. But on the edges of the image some surrounding pixels don't exist. You can see this diffusion here:

Dorrer and Zuegel processing.png

As you can see in the left bitmap the error is diffused to the surrounding unprocessed pixels. But on the edges these surrounding pixels don't exist.

 

I want to do this using case-structures. My goal is this type of algorithm:

 

If x = 0 and y < m-1 then do not pass the error for these pixels on.

 

But getting this to work is quite difficult. I tried using a case structure in a case structure, but these levels of case structures give me the error of 'change to default if empty'. How can I get this to work?

 

So to rephrase my question: I want error elements not to be passed on if the coordinates of the pixel being processed are on the edge of my image. How can I get this to work?

 

For some more background on my program:

As explained I calculate a binary value for each pixel. This rounding to a 0 or 1 induces an error, for example: the pixel is supposed to be 80%, but the pixel can only be a 0 or a 1. So it's rounded to 100%. This induces an error of 20%. This 20% is then weighed and then diffused to the surrounding pixels.

This diffusion was a hard thing to program in Labview so what I did was this:

I took the image array and multiplied it with zero. Now I have an error that is exactly the same size as the image array but now it's completely empty. Let's call it the error array.

Then I will add the found error to the respective surrounding coordinates. For that I have to find the coordinates of these surrounding pixels.

 

I do this by taking the current pixel coordinates and add to that either -1, 0 or 1 so I can get the index for the respective surrounding pixel, for example pixel x+1,y+1. Now because some of the pixels are on the edges, I can't just take (x-1,y+1) every time. In these cases I don't want the error to be passed on to the surrounding pixels because these surrounding pixels don't exist. 

0 Kudos
Message 1 of 6
(2,575 Views)

When diffusing the error you have 7 cases, X=0 && Y!=0, X=Max && Y!=Max, X !=0 && Y=0, X!=Max && Y=Max, X=0 && Y=0, X=Max && Y=Max, default.

In the first 6 one (two) direction isn't calculated, the rest count as normal in default.

You can check all and create a boolean array of the result, then bool array to number and wire it to a case structure, with the above 7 cases numbered.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 6
(2,561 Views)

Do you have an example or anything like that? I tried to make one but I am not sure how to combine multiple boolean outputs into one output and then put that into an array. My current attempt was trying to get it to work the way I have already described:

Labview not working.png

The error it shows is that I hooked up two different arrays. That is strange because the output of the case structure should be a single element, not an array. The autoindexing at the edges of the for loops should have made a single elementof the array-type data that is coming from the left (arrays that are one element in size).

 

What am I doing wrong here?

0 Kudos
Message 3 of 6
(2,519 Views)

Hello Choisai,

 

Can you let me know if this thread is still active?

If this is the case, then please let me know where I can help you at this moment.

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
Message 4 of 6
(2,404 Views)

I presume you understand what I am trying to do here, so any commentary on my program is welcome.

I want to diffuse the error over the surrounding unprocessed pixels. On the edges this must be different because several pixels are the not available. What I did to realize this is by instead diffusing the error to the surrounding pixels, I diffuse the unused error to the very first pixel: pixel (x=0, y=0).

 

So I first hook the input of the x-coordinates and Y-coordinates up to case structures (is x=0? If yes, then following question) to find out where the respective pixel is located. Let's say it is located in the right bottom corner. Then there are no pixels to which the error of the calculation can be diffused. So instead of then taking x and y and adding or subtracting 1 of them (for example: x+1,y+1 for the pixel under and to the right of the pixel that is being processed) the coordinates are taken to be zero so the error is diffused to the first pixel.

 

This has one major issue

Because I am using the replace subset function, I replace one error with another. I want them to add together. If you have any advice that would be great! You can check out my program in its current form, for I have added it to this message.

 

PS: The program also contains an attempt at opening a DLL file. That does not work at the moment so you can ignore that or even delete it if you want.

PPS: The program requires the Vision module of Labview

0 Kudos
Message 5 of 6
(2,389 Views)

Hello Choisai,

 

Thanks for sharing the code.

I cannot really run the code (missing DLL), but now I have an idea at what your code looks like.

 

You could have made the code easier to write if you would have created one case structure with the 7 different cases (for example linked to a type defined enum) like Yamaeda mentioned above.

To determine in which one you are you could just use the knowledge of your x and y value and determined in a subVI  right state/case to execute.

 

Then your code would have basically been:

- 2 nested for-loops (for X and Y direction)

- One subVI to determine state in the inner for loop

- the output "state" of this subVI wired to a case structure

- a case structure with 7 cases which correspond to the 7 possible states/cases

- In each case you then have the appropriate code (probably again in subVIs)

 

So what you want to do is

- Get the existing ("old") array subset at the right position (use "Array Subset" VI)

- Add the new array subset and the "old" one by using the "Add" VI.

- Then use the "Replace Array Subset" VI.

 

There can be more optimal ways of doing, but this would be one of the simplest and most readable way to add this at this moment in this code.

 

 

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
0 Kudos
Message 6 of 6
(2,350 Views)