MATLAB: Identifying Black Markings on Grey Surface

image analysisimage processingImage Processing Toolboximage segmentation

Hello all! I am tasked with identifying black markings on this gray surface. My current plan is to identify the markings and classify them using their intensity values in relation to the gray surface. However, I am having trouble because the gray surface image is not uniformly colored and the markings are also different shades of grey. If anyone has any ideas as to how I can go about this, that would be great!
Here is the image: http://i.imgur.com/nEQCv.jpg
Here is my code so far: clc;
rect = [70 0 570 478];
rect2 = [0 0 530 478];
I = imread('test2.jpg');
I = imcrop(I, rect);
I = imcrop(I, rect2);
H = fspecial('unsharp');
I = imfilter(I,H,'replicate');
I = rgb2gray(I);
figure
imtool(I);
I(I>=90)=255;
I(I<80)=20;
figure
imshow(I);

Best Answer

I'd try to get the background and then divide by it. Lots of ways you could try to get the background. You could use 2D polynomial fit ( http://www.mathworks.com/matlabcentral/fileexchange/34765-polyfitn). You could try morphological closing with imclose(). You could try Savitzky-Golay filter with sgolay(). You could try blurring with imfilter() or conv2(). You could try CLAHE with adapthisteq() etc. Try them all and see how they look. Each one is only a few lines of code - I'm sure you can handle it.
Then divide your image by your background image to get a flat field image. Then threshold, call bwlabel, and finally call regionprops to measure various things about each mark.