Question

I am looking for some measurements to do to distinct between these two binary images (texte and noise).

enter image description here

Hough transform of the frequency domain don't tell me much (either in skeleton or in the original shape), as can be seen below !

enter image description here

in the spatial domain, I have try to measure, if a given pixel participate to line or curve, or participate to a random shape, and then measures the percentage of all pixels participating and not participating to normal shape (lines and curves) to distinguish between these images, but I didn't succeed, in implementation.

what do you think ?

I use matlab for test.

Thanks in advance

Was it helpful?

Solution

Looking at the skeleton images, one could notice how the noise image has lots of branches in it, as compared to the text image and this looks like one of the features that could be exploited. The experiment as code shown below soughts to verify the same, using the OP's images -

Experiment Code

%%// Experiment to research what features what might help us 
%%// differentiate betwen noise and text images

%%// Read in the given images
img1 = imread('noise.png');
img2 = imread('text.png');

%%// Since the given images had the features as black and rest as white, 
%%// we must invert them
img1 = ~im2bw(img1);
img2 = ~im2bw(img2);

%%// Remove the smaller blobs from both of the images which basically
%%// denote the actual noise in them
img1 = rmnoise(img1,60);
img2 = rmnoise(img2,60);

%// Get the skeleton images
img1 = bwmorph(img1,'skel',Inf);
img2 = bwmorph(img2,'skel',Inf);

%%// Find blobs branhpoints for each blob in both images
[L1, num1] = bwlabel(img1);
[L2, num2] = bwlabel(img2);
for k = 1:num1
    img1_bpts_count(k) = nnz(bwmorph(L1==k,'branchpoints'));
end
for k = 1:num2
    img2_bpts_count(k) = nnz(bwmorph(L2==k,'branchpoints'));
end

%%// Get the standard deviation of branch points count
img1_branchpts_std = std(img1_bpts_count)
img2_branchpts_std = std(img2_bpts_count)

Note: Above code uses a function - rmnoise shown below that is built based on the problem discussed at this link :

function NewImg = rmnoise(Img,threshold)

[L,num] = bwlabel( Img );
counts = sum(bsxfun(@eq,L(:),1:num));
B1 = bsxfun(@eq,L,permute(find(counts>threshold),[1 3 2]));
NewImg = sum(B1,3)>0;

return;

Output

img1_branchpts_std =
   73.6230

img2_branchpts_std =
   12.8417

One can see the big difference between the standard deviations of the two input images, suggesting this feature could be used.

Runs on some other samples

To make our theory a bit more concrete, let's use a pure text image and gradually add noise and see if the standard deviation of branch-points, naming it as check_value suggest anything on them.

(I) Pure text image

enter image description here check_value = 1.7461

(II) Some added noise image

enter image description here

check_value = 30.1453

(III) Some more added noise image enter image description here

check_value = 54.6446

Conclusion: As can be seen, this parameter provides quite a good indicator to decide on the nature of images.

Finalized Code

A script could be written to test for whether another input image would be a text or noise one, like this -

%%// Parameters
%%// 1. Decide this based on the typical image size and count of pixels 
%%// in the biggest noise blob
rmnoise_threshold = 60; 

%%// 2. Decide this based on the typical image size and how convoluted the
%%// noisy images are 
branchpts_count_threshold = 50; 

%%// Actual processing
%%// We are assuming input images as binary images with features as true 
%%// and false in rest of the region
img1 = im2bw(imread(FILE)); 
img1 = rmnoise(img1,rmnoise_threshold);
img1 = bwmorph(img1,'skel',Inf);

[L1, num1] = bwlabel(img1);
for k = 1:num1
    img1_bpts_count(k) = nnz(bwmorph(L1==k,'branchpoints'));
end

if std(img1_bpts_count) > branchpts_count_threshold
    disp('This is a noise image');
else
    disp('This is a text image');
end

OTHER TIPS

And now what you suggest if we try to use the original shape instead of the skeleton, (to avoid the loss of information). I try to measure for a given pixel, the elongation of the strokes (instead of straight branches) that past throughout that pixel, by counting the number of transitions from white to black in a clockwise.

I am thinking to use a circle with a radius, and for the origin the pixel in consideration, and store the pixels locating at the edge of the circle in an ordered list (clockwise) and then compute the number of transitions (black to white) from this list.

by increasing the radius of the circle we could trace the shape of elongated stokes and know his orientation.

this is a schema illustrating this. the pixels that have a number of transitions equal to 0 or bigger than 2 (red ones) have to be classified as noise, and those that have 2 or 1 transition classified as normal.

enter image description here

What do you think of this approach !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top