Multilevel image thresholding combining distinct colors
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Kasthuri Kannan
am 30 Okt. 2019
Kommentiert: KALYAN ACHARJYA
am 8 Nov. 2019
I am trying to segment an image. It has 8 distinct colors (regions) excluding the background white. I am using multilevel thresholding with 8 levels out of which 6 regions are segmented properly. However, the method combines two regions which is highlighted in circles. Clearly, the grayscale image (middle) also shows the difference for this region. I am not sure how to get this regions segmented along with the rest of the regions. Any help will be much appreciated. I am also reproducing the code below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/245758/image.png)
% Read the image and convert into grayscale
I = imread(filepath)
I = rgb2gray(I);
% Define thresholds for the 8 distinct regions excluding the white background
thresh = multithresh(I,8)
% Segment the image and display
seg_I = imquantize(I,thresh);
imshow(seg_I == 6)
2 Kommentare
KALYAN ACHARJYA
am 31 Okt. 2019
Bearbeitet: KALYAN ACHARJYA
am 2 Nov. 2019
There are distinct difference between those two labels in the circles (2nd Image).
Akzeptierte Antwort
Kritika Bansal
am 6 Nov. 2019
Hi,
I tried replicating the issue on my end, but the output comes out to be correct in my case when I ran the following commands on MATLAB Online R2019b.
These are the commands I used:
clear all; clc;
I=imread('input.png');
imshow(I);
I = rgb2gray(I);
% Define thresholds for the 8 distinct regions excluding the white background
[thresh, metric] = multithresh(I,8)
% Segment the image and display
seg_I = imquantize(I,thresh);
figure, imshow(seg_I, []);
figure, imshow(label2rgb(seg_I));
Following is the output:
thresh =
1×8 uint8 row vector
23 61 90 116 146 168 182 219
metric =
0.9982
I am also attaching the input and output images for your reference.
![input.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247007/input.png)
![seg_I.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247008/seg_I.png)
![label2rgbOutput.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247009/label2rgbOutput.png)
2 Kommentare
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!