I = imread('Original_crackes.jpg');
Im = rgb2gray(I(130:700,450:1000,:));
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;
[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;
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
Best Answer