Classifying grainy and defected marbles
3 views (last 30 days)
Show older comments
Hello everyone, i'm trying to classify grainy texture and defects on marbles. The code should understand the differences between grainy textures and cracks.
In the code, it finds all the textures. How can I distinguish cracks from grainy texture. Can anyone help me?
i=imread('image1.jpg');
figure
imshow(i)
title('Original image before processing')
I = rgb2gray(i);
bw = edge(I, 'Canny', 0.27);
figure
imshow(bw)
title('Edges of Original Image Canny Method')
BW_out = bwpropfilt(bw, 'Area', [150 + eps(200), Inf]);
BW_out = bwpropfilt(BW_out, 'Perimeter', [70 + eps(100), Inf]);
properties = regionprops(BW_out, {'Area', 'Eccentricity', 'EquivDiameter', 'EulerNumber', 'MajorAxisLength', 'MinorAxisLength', 'Orientation', 'Perimeter'});
figure
imshow(BW_out)
title('Crack extracted')
5 Comments
Image Analyst
on 19 May 2021
See my Image Segmentation Tutorial in my File Exchange.
Adapt it to use your image.
Answers (1)
Satyam
on 26 Feb 2025
To extract grains and cracks from an image and superimpose them, start by reading and converting the image to grayscale. Use the Canny edge detection method to identify edges, which include both cracks and potential grain boundaries. Apply morphological property filtering to isolate cracks based on area and perimeter, and then dilate these regions to include their surroundings. Enhance the contrast of the image and remove the dilated cracks to focus on grain detection. Smooth the image using Gaussian filtering, and apply adaptive thresholding to identify grainy areas. Remove small noise elements and optionally dilate the grain mask to connect nearby regions. Finally, superimpose the detected cracks and grains on the original image.
Here is the modification of the provided code which tries to achieve the same.
i = imread('image1.jpg');
figure;
imshow(i);
title('Original Image Before Processing');
I = rgb2gray(i);
bw = edge(I, 'Canny', 0.27);
figure;
imshow(bw);
title('Edges of Original Image Canny Method');
BW_out = bwpropfilt(bw, 'Area', [150 + eps(200), Inf]);
BW_out = bwpropfilt(BW_out, 'Perimeter', [70 + eps(100), Inf]);
figure;
imshow(BW_out);
title('Crack Extracted');
% Dilate the crack mask to include surrounding areas
se = strel('disk', 5);
dilatedCracks = imdilate(BW_out, se);
% Enhance contrast to better visualize grainy textures
enhancedI = imadjust(I);
% Remove dilated cracks from the enhanced image
enhancedI(dilatedCracks) = 0;
% Apply Gaussian filtering to smooth the image
smoothedI = imgaussfilt(enhancedI, 2);
% Use adaptive thresholding to identify grainy areas
adaptiveThresh = adaptthresh(smoothedI, 0.5);
grainMask = imbinarize(smoothedI, adaptiveThresh);
% Remove small objects to reduce noise
grainMask = bwareaopen(grainMask, 5);
% Optionally, dilate to connect nearby grainy regions
grainMask = imdilate(grainMask, strel('disk', 5));
% Superimpose cracks and grains on the original image
figure;
imshow(i);
hold on;
% Highlight crack areas in red
visboundaries(BW_out, 'Color', 'r', 'LineWidth', 1);
% Highlight grainy areas in green
visboundaries(grainMask, 'Color', 'g', 'LineWidth', 1);
hold off;
title('Cracks (Red) and Grainy Texture (Green) Superimposed on Original Image');
I hope it was helpful.
0 Comments
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!