2

I wants to detect lines from an image with black line drawing over white papers. It could be easy if its ideal 'black and white', using histogram threshold would do.

But, as the image attached shows, some lines (e.g. in the light red circle) are in gray lighter than the shades (e.g. in the dark red circle). So some shades are obtained before light lines using histogram threshold.

Shades darker than some Lines.

Is there any ideas to divide lines from shades with some 'knowledge'? Thanks!


Edit: Here are the raw images, a bit small because they are of original resolution.

lines.bmp shades.bmp

Thanks :-)

weiwen
  • 446
  • 6
  • 16
  • can you upload the raw image without the red circle? – lennon310 Dec 27 '13 at 05:06
  • @lennon310 Thanks! I had uploaded. Now I'm thinking that one difference between an 'edge' pixel and a 'shade' pixel may be: The difference between this pixel's value and its neighbourhood's mid-value. I'm having a try now. – weiwen Dec 27 '13 at 06:36
  • 1
    Duplicate? http://stackoverflow.com/questions/4632174/what-processing-steps-should-i-use-to-clean-photos-of-line-drawings – Niki Dec 27 '13 at 07:29
  • @nikie Oh! I think my problem is very similar to that one, and the method seems helpful. Thanks Very Much! – weiwen Dec 27 '13 at 07:46
  • @nikie Inspired by your [answer](http://stackoverflow.com/a/4633884/2918210), I think I have already achieved a better result through Img-medianBlur(Img), thanks a lot :-) I still have two little questions, 1. Should one line of your code be changed to `opened = imdilate(imerode(blue,mask),mask);` cause we do erosion before dilation? 2. I understand the morphological operation over 'binary' images, but can't imagine how to erosion/dilation a 'gray' image (and the 'open' blur method in your answer). Could you guide me a little about this? Thanks again. – weiwen Dec 27 '13 at 11:29
  • @Veslam: I think this answers both of your questinos: http://dsp.stackexchange.com/questions/1932/what-are-the-best-algorithms-for-document-image-thresholding-in-this-example/1934#1934 – Niki Dec 27 '13 at 12:20
  • @Veslam: A median filter is good for approximating a "white image", too, as long as less than half the pixels in every k*k window are "foreground" pixels (lines or text). If the lines you want to discover get thicker, you have to increase the filter size k, which can become very expensive very fast. – Niki Dec 27 '13 at 12:28
  • @nikie I'll learn from it, thank you :-) – weiwen Dec 27 '13 at 15:37

1 Answers1

1

I would add another method using Gaussian blur other than erosion+dilation, for your reference:

file='https://i.stack.imgur.com/oEjtT.png';
I=imread(file);
h = fspecial('gaussian',5,4);
I1=imfilter(I,h,'replicate');
h = fspecial('gaussian',5);
I2=imfilter(I,h,'replicate');
I3=I1-I2;
I3=double(I3(:,:,1));
I3=I3.*(I3>5);
imshow(I3)

enter image description here

lennon310
  • 12,503
  • 11
  • 43
  • 61