2

Let's assume I have 2 matrices, which are representing a signalling with 1 and 0 in a 2D space.

A = [1,1,0,0;1,1,0,0;1,1,0,0];
A =

 1     1     0     0
 1     1     0     0
 1     1     0     0

B = [1,0,1,1;1,0,0,1;1,0,0,0];
B =
 1     0     1     1
 1     0     0     1
 1     0     0     0

Matrix A seems to cluster the signal, while matrix B is more random distributed. My goal is to identify noise with this approach in images, which should be much less structured than real signal.

Is there regionprops function which can do that? Any other suggestions?

My approach so far:

  • Measure distances between the positive patches (get average)
  • Use bwareafilt to detect the biggest patch.
C.Colden
  • 627
  • 1
  • 8
  • 28

2 Answers2

0

I used a black and white image in which blackish was text and blackish was noise. I just bruteforced for pixel wise checking in the code. Idea is:

If any non-white pixel is surrounded by 5 or more whitish(thr value>230) pixel, consider it noise and make it white.

for k=1:num_you_like 
c=0; img_inp=img_final;

for i=2:(length(img_inp(:,1))-1)
    for j=2:(length(img_inp(1,:))-1)
if(img_final(i,j)<255)
    if (img_inp(i-1,j)>230)
        c=c+1;
    end
    if (img_inp(i+1,j)>230)
        c=c+1;
    end
    if (img_inp(i,j-1)>230)
        c=c+1;
    end
    if (img_inp(i,j+1)>230)
        c=c+1;
    end
    if (img_inp(i-1,j-1)>230)
        c=c+1;
    end
    if (img_inp(i-1,j+1)>230)
        c=c+1;
    end
    if (img_inp(i+1,j-1)>230)
        c=c+1;
    end
    if (img_inp(i+1,j+1)>230)
        c=c+1;
    end
    if c>5
      img_final(i,j)=255;
    end
    c=0;
end
end
end

originalfor num_you_like=1

For different threshold of whitish(here i took 230) and different iterations, you can try and see the change. Though this was just a observation in my image and i felt like your matrix is cluster of black with some random whites...

It would be easier to answer i we knew what the images are like, maybe add in your question, and comment on usefulness of the answer.

Pranav Totala
  • 148
  • 2
  • 14
0

It may be a naive approach but what about considering multiplying binary matrice with flipped version of it:

d = ( A .* flipud(fliplr(A)) ) / numel(A);

If 1 and 0 are randomly distributed, there are as many chances that you will have 1x1 or 1x0. If data are more clustered it is more likely that 1x0 will be more prevalent. So randomly distributed data will have d close to 0.5

Flipping may not work in all cases, for instance:

0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 1 1 0 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0

but you can do circshift for different lags ... if all lags are in average close to 0.5 it is likely that 1 and 0 are randomely distributed.

You question makes me think of evaluating the entropy of your binary data and here is similar question on stackexchange that I come through and that may provide more ideas :

https://stats.stackexchange.com/questions/17109/measuring-entropy-information-patterns-of-a-2d-binary-matrix

CitizenInsane
  • 4,755
  • 1
  • 25
  • 56