MATLAB: Extracting Cracks

cracks

Hi,
I am working on an image which has pores and cracks. I was able to extract the pores excluding the cracks. Now I have to extract only the cracks. Is there any way to do this, that is to extract only cracks.
Below are the two images – 1st is the original image and second is the image which has only pores.
Below is the link for the image which has cracks rounded with brown color.

Best Answer

Hi Ratna, It's quite difficult due to the relative intensities - cracks are only a "little" bit lighter than solid material. Here's my solution, which utilises Dirk Kroon's Frangi Vessel Filter on the FEX.
Sorry, I'm in a rush so I don't have time to comment it, but it's relatively short - hopefully you can follow line-by-line.
I've needed to put some pretty specific thresholds. I have no idea how it will work with "similar but different" images.
I = imread('Original_crackes.jpg');
Im = rgb2gray(I(130:700,450:1000,:)); % Clear away the border
Im_limited = double(min(max(200,Im),255));
Im_closed = imclose(Im_limited, ones(8));
Im_diff = Im_closed - Im_limited;
BW_holes = imopen(Im_limited<205,ones(4));
BW_pores = imclearborder(BW_holes);
Im_diff(imdilate(BW_holes,ones(10))) = 0;
% Get vessels
[Im_edgeEnhanced,Scale,Direction] = FrangiFilter2D(Im_diff/max(Im_diff(:)),struct('BlackWhite',false));
BW_cracks = bwareaopen(Scale==2, 50) & ~imdilate(BW_holes,ones(10));
CC = bwconncomp(BW_cracks);
stats = regionprops(CC, Im_edgeEnhanced,'Eccentricity','MaxIntensity','Orientation')
keepMask = [stats.Eccentricity]>0.983;
BW_cracks(cat(1,CC.PixelIdxList{~keepMask})) = false;
% Display
figure
subplot(1,3,1), imagesc(Im_limited), axis image
subplot(1,3,2), imagesc(BW_pores), axis image
subplot(1,3,3), imagesc(BW_cracks), axis image