LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get percentage difference between two matrices?

Solved!
Go to solution

Good day everyone, I just want to ask how to get the percentage difference between two binary matrices. This is for comparing two images converted to matrices in LabView. Thank you. 

0 Kudos
Message 1 of 10
(6,086 Views)

You can use the normal mathematical operators on arrays as well. I've attached an example.

Best regards,

Jarle Ekanger, MSc, PhD, CLD
Flow Design Bureau AS

- "The resistance of wires in LabVIEW is not dependent on their length."
0 Kudos
Message 2 of 10
(6,076 Views)

@pinkman wrote:

Good day everyone, I just want to ask how to get the percentage difference between two binary matrices. This is for comparing two images converted to matrices in LabView. Thank you. 


You probably converted it to a 2D array (A matrix in LabVIEW has a special meaning).

 

"Binary" is not very well defined (unless you are looking for the number of bits that are different). What is the datatype? Was it a color image or a greyscale image? Are both arrays the same size?

 

How do you define "percentage difference"? Which one of the two is the 100% reference?

 

  1. Do you want a new 2D array where each element is the difference of the second array compared to the first (or vice versa), expressed in percentages?
  2. Do you want to know what percentage of array elements are different between the two arrays?
  3. Do you want to know the average difference between all array elements?

All possible interpretations can be easily solved with very little code, but you need to explain in more detail what you actually want?

 

Here is a simple solution for case #2, for example (assuming the array have the same size, and we only want a rought estimate, rounded down to the nearest integer percent):

 

 

0 Kudos
Message 3 of 10
(6,051 Views)

I believe that's what we needed, thank you sir. The only problem is that we use a very high resoultion for the images(2562x2050), and we use it through comparing two PCB patterns in grey scale. Is there a way to exclude the zeroes in the 2d array when we obtain the percentage difference? Because when the resolution is very high, the patterns of the PCB seems too small compared to the whole PCB, so it produces a lot of zeroes against ones.

 

We tested to get the percentage difference between the images below(attached), we got a value of 2% even though their patterns are too different.

 

Your help is greatly appreciated, thank you sir.

Download All
0 Kudos
Message 4 of 10
(5,996 Views)

I cannot see the color map. Are the zeroes white? Are all mistakes whilte?

 

What you can do is divide by the number of black pixels in the reference image.

 

Instead of "array size", use a "not equal zero" on the reference array and divide by that number instead. See if it works.

0 Kudos
Message 5 of 10
(5,987 Views)

Yes sir, the white are zeroes and the black are ones. We threshold the images before comparing, so the white part becomes black and the black part becomes red. And sir, what do you mean by divide by the number of black pixels in the reference image? Basically, we want to compare the pixels of the red part from the two images with respect to its position. 

 

Thank you sir.

0 Kudos
Message 6 of 10
(5,972 Views)

So, what kind of percentage would you expect for the two images? They are not fully thresholded, because there are a significant amount of elements that are neither x000000 or xFFFFFF. 

0 Kudos
Message 7 of 10
(5,959 Views)

Sir we are trying to get the percent difference of the image with respect to the template, but we only want to compare the patterns, so it excludes all zeroes. The image is being process through thresholding before we get the percent difference.

 

Thank you sir.

0 Kudos
Message 8 of 10
(5,929 Views)
Solution
Accepted by pinkman

Well, in the current picture the interesting pixels are zero in the reference image. Here's a quick example that would take all zero pixels as 100%, then look at the same pixels in the other image to see how many are still 0.

 

Modify as needed.

 

Download All
Message 9 of 10
(5,920 Views)

That is what we need.

 

Thank you sir!

 

And sir, can you hel me with this one?http://forums.ni.com/t5/LabVIEW/Is-there-a-way-to-locate-segments-from-a-reference-image-to/td-p/218...

0 Kudos
Message 10 of 10
(5,896 Views)