can some help me please with Otsu thresholding matlab code in which the dimensions, width, height, of the output image is equal to the orignal image (input image). Thanks in advance.
Afficher commentaires plus anciens

15 commentaires
Walter Roberson
le 22 Nov 2018
please post your code
Arshad Ali
le 22 Nov 2018
Arshad Ali
le 22 Nov 2018
Walter Roberson
le 22 Nov 2018
No, in that code, bw is certain to be exactly the same height and width as the original image, I. However, bw will be black and white (2D) instead of color (3D). If you need the exact same output dimensions then
I_out = repmat( im2uint8(bw), [1 1 3]);
Arshad Ali
le 23 Nov 2018
Arshad Ali
le 23 Nov 2018
Image Analyst
le 23 Nov 2018
The deprecated im2bw() does not change the number of rows and columns in the image. What is the size you say it's giving and what size do you think it should be?
Arshad Ali
le 23 Nov 2018
Walter Roberson
le 23 Nov 2018
it looks to me as if you are using saveas or print or getframe on the displayed image and then complaining that it is not the same size as the original .
Image Analyst
le 23 Nov 2018
Good guess Walter - that's probably it. When I use "whos" to look at the I and bw variable:
Name Size Bytes Class Attributes
bw 256x320 81920 logical
Name Size Bytes Class Attributes
I 256x320x3 245760 uint8
You can see that they're both 256 by 320 - the same lateral size (rows and columns), NOT different.
Arshad, WHY do you say they're of a different size? How did you check that? Please supply proof.
Arshad Ali
le 24 Nov 2018
Arshad Ali
le 24 Nov 2018
Arshad Ali
le 24 Nov 2018
Walter Roberson
le 24 Nov 2018
how are you saving the output image ?
Arshad Ali
le 24 Nov 2018
Réponses (1)
KALYAN ACHARJYA
le 22 Nov 2018
Hello Arshad, otsu thresolding techniqie is very popular thresholding approach in image segmentation domain. I have posted the following code from Gonzalez book (Digital Image Processing using Matlab), requested you to refer the book for detail explanation.
function [T,SM]=otsuthresh(h);
h=h/sum(h);
h=h(:);
i=(1:numel(h))';
P1=cumsum(h);
m=cumsum(i.*h);
mG=m(end);
sigSquared=((mG*P1-m).^2)./(P1.*(1-P1)+eps);
maxSigsq=max(sigSquared);
T=mean(find(sigSquared==maxSigsq));
T=(T-1)/(numel(h)-1);
SM=maxSigsq/(sum(((i-mG).^2).*h)+eps);
end
Catégories
En savoir plus sur Image Arithmetic dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!.png)

