how to find threshold values in an image?

10 visualizzazioni (ultimi 30 giorni)
Catarina Isabel Leitão
Catarina Isabel Leitão il 15 Set 2018
Commentato: KALYAN ACHARJYA il 16 Set 2018
how to find threshold values in an image, with the following ranges: 0-0.25, 0.25-0.50,0.50-0.75 and 0.75-1? And they could tell me what makes the following code please:
GRAY = mat2gray(bEnhanced);
% figure,
% imshow(GRAY),
% title('Gray Image');
threshold = graythresh(GRAY);
disp(threshold)
threshold
BW = imbinarize(GRAY, threshold*(1.1+threshold));
c = BW;
% figure,
% imshow(BW),
% title('Binary Image');
BW = ~ BW;
% figure,
% imshow(BW),
% title('Inverted Binary Image');
[B,L] = bwboundaries(BW,'holes');
STATS = regionprops(L, 'all'); % we need 'BoundingBox' and 'Extent'
% pixelVals = regionprops(c,'MeanIntensity');
% Step 7: Classify Shapes according to properties
% Square = 3 = (1 + 2) = (X=Y + Extent = 1)
% Rectangular = 2 = (0 + 2) = (only Extent = 1)
% Circle = 1 = (1 + 0) = (X=Y , Extent < 1)
% UNKNOWN = 0
% figure,
% imshow(RGB),
% title('Results');
im=bEnhanced;
pixelVals=regionprops(L,im,'MeanIntensity');
axes(handles.img_bw);
imshow(GRAY);
hold on
for i = 2 : length(STATS) %ignore idx=1, because that's the whole image
% W(i) = uint8(abs(STATS(i).BoundingBox(3))>4 && abs(STATS(i).BoundingBox(4)) > 4);
% W(i) = W(i) + 2 * uint8((STATS(i).Extent - 1) == 0 );
centroid = STATS(i).Centroid;
if(abs(STATS(i).BoundingBox(3))>8 && abs(STATS(i).BoundingBox(4)) >8)
plot(centroid(1),centroid(2),'wX','Color', 'red');
bb = STATS(i).BoundingBox;
rectangle('Position', bb,...
'EdgeColor', 'red', 'LineWidth', 1)
% visboundaries(B,'LineWidth',0.1);
% pixelVals(i).MeanIntensity
density = ((pixelVals(i).MeanIntensity*100)/255);
t = text(centroid(1),centroid(2),strcat(num2str(density)),'Color','red');
%t = text(centroid(1),centroid(2),strcat(num2str(density),'% ----- ' , num2str(i)),'Color','black');
t.FontSize = 15;
end
end
hold on
img=getimage(handles.img_gray);
hold off
  1 Commento
KALYAN ACHARJYA
KALYAN ACHARJYA il 16 Set 2018
Check the Gonzalez Book (With Matlab)-Chapter 10: Image Segmentation (Page 516 in Second Edition), you will get the threshold values.

Accedi per commentare.

Risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by