Image segmentation using thresholding

I have raw image of rocks like the one on the right, I want a code to get the result on the left

3 Kommentare

Cris LaPierre
Cris LaPierre am 19 Apr. 2024
What do the different colors correspond to?
Have you tried using the Color Threshholder app? Here's an example that you might find useful
Aisha Al Ghurabi
Aisha Al Ghurabi am 20 Apr. 2024
Rlue : Pores
Red: Grains
Green: in between
DGM
DGM am 21 Apr. 2024
Hmm. There may be some better way of doing the classification, but I don't know what it would be. The gray levels that I estimated from the example image seems fairly plausible, though it might be worth trying to adjust them. I am also not really sure what subsequent steps need to be performed on these labeled regions; consequently, I'm not really sure how exact they need to be.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

DGM
DGM am 19 Apr. 2024
Bearbeitet: DGM am 19 Apr. 2024

0 Stimmen

Since we're playing guessing games, here's my guess.
% you might have an actual image, but all we have is a screenshot
inpict = imread('image.bmp');
inpict = imcrop(inpict,[3.51 23.51 703.98 471.98]); % crop off the border
% split the two halves
A = im2gray(inpict(:,352+1:end,:)); % input
B = inpict(:,1:352,:); % output
% look at the hue of the output sample
[H,~,~] = rgb2hsv(B);
H = mod(H+0.2,1); % rotate to keep the red peak from wrapping across zero
imhist(H)
% split the histogram between the peaks
mkr = H < 0.25;
mkb = H > 0.80;
mkg = H > 0.45 & H < 0.6;
% sample the source in those regions
Ar = A(mkr);
Ag = A(mkg);
Ab = A(mkb);
subplot(3,1,1), imhist(Ar)
subplot(3,1,2), imhist(Ag)
subplot(3,1,3), imhist(Ab)
% the bins actually overlap quite a bit
% we don't know if that's due to scaling/registration errors
% or whether the classification is done differently
levels = [90 180]; % pick some bin edges
CT = [0 0 1; 0 1 0; 1 0 0]; % a color table
indpict = imquantize(A,levels); % an indexed image
figure
imshow(indpict,CT) % show it

Produkte

Version

R2024a

Gefragt:

am 19 Apr. 2024

Kommentiert:

DGM
am 21 Apr. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by