How to find Threshold values in an image in Matlab?

Asked

Viewed 53 times

0

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 could you tell me what the following code does 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
  • Our language is the Português. Translate your question.

  • 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 could you tell me what the following code does please

  • Catarina, click on EDIT and translate the question. Leave in English and comment here does not resolve and your question can still be closed.

  • The title was missing too

  • Okay, thanks, I’m new here and I didn’t know :/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.