imbase = ['../text/images/']; % Segmentation by histograsm thresholding f = imread([imbase,'coins.tif']); f1 = double(f); [N1 X1] = hist(f1(:),256); f = imread([imbase,'bacteria.tif']); f2 = double(f); [N2 X2] = hist(f2(:),256); figure(1);clf; subplot(221);imagesc(f1);colormap gray;axis image subplot(222);imagesc(f2);colormap gray;axis image subplot(223);plot(X1,N1); subplot(224);plot(X2,N2); figure(2);clf; subplot(221);imagesc(f1);colormap gray;axis image subplot(222);imagesc(f2);colormap gray;axis image subplot(223);imagesc(f1>150);colormap gray;axis image subplot(224);imagesc(f2>100);colormap gray;axis image % Variance as a measure of similarity g = fspecial('gaussian',15,4); f1 = filter2(g,5*randn(256)); f2 = filter2(g,.5*randn(256)); [n1 x1] = hist(f1(:),256); [n2 x2] = hist(f2(:),256); close all;figure(1);clf; colormap gray subplot(221);imagesc(f1);caxis([-1.5 1.5]); subplot(222);imagesc(f2);caxis([-1.5 1.5]); subplot(223);plot(x1,n1);a1 = axis; subplot(224);plot(x2,n2); a2 = axis; axis([a1(1) a1(2) a2(3) a2(4)]); print -djpeg ~/Desktop/var.jpg var(f1(:));var(f2(:)) % Plot some histograms a = lognrnd(1*ones(1e4,1),.3*ones(1e4,1)); [N,X] = hist(a,50); figure(1);clf;colormap default bar(X,N/length(a),1); [mean(a) var(a)] f = imread([imbase,'bacteria.tif']); f2 = double(f); [N2 X2] = hist(f2(:),256); N2 = N2(:); plot(X2,N2); print -djpeg ~/Desktop/histex.jpg % Otsu % Segmentation by histograsm thresholding f = imread([imbase,'coins.tif']); f1 = double(f); [N1 X1] = hist(f1(:),256); sigw1 = otsu(N1); [v1 t1] = min(sigw1); f = imread([imbase,'bacteria.tif']); f2 = double(f); [N2 X2] = hist(f2(:),256); sigw2 = otsu(N2); [v2 t2] = min(sigw2); figure(1);clf; subplot(221);imagesc(f1);colormap gray;axis image subplot(222);imagesc(f2);colormap gray;axis image subplot(223);plot(X1,sigw1); subplot(224);plot(X2,sigw2); print -djpeg ~/Desktop/otsu1.jpg figure(2);clf; subplot(221);imagesc(f1);colormap gray;axis image subplot(222);imagesc(f2);colormap gray;axis image subplot(223);imagesc(f1>t1);colormap gray;axis image subplot(224);imagesc(f2>t2);colormap gray;axis image print -djpeg ~/Desktop/otsu2.jpg figure(2);clf; subplot(221);imagesc(f1);colormap gray;axis image subplot(222);imagesc(f2);colormap gray;axis image subplot(223);imagesc((f1>t1)-(f1>150));colormap gray;axis image subplot(224);imagesc((f2>t2)-(f2>100));colormap gray;axis image print -djpeg ~/Desktop/otsu3.jpg