Classifying grainy and defected marbles

3 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2021-5-19
See my Image Segmentation Tutorial in my File Exchange.
Adapt it to use your image.
matlablearner
matlablearner 2021-5-19
Thanks for answering, but the tutorial is complicated for me. How should I adapt it to my image to segment it into cracks and veins?

请先登录,再进行评论。

回答(1 个)

Satyam
Satyam 2025-2-26
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.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by