Borrar filtros
Borrar filtros

Adaptive Threshold for Segmentation

4 visualizaciones (últimos 30 días)
nazneen
nazneen el 20 de Feb. de 2015
Comentada: Image Analyst el 24 de Sept. de 2020
I have a piece of code which works perfectly fine but i am not able to understand the part where it creates a threshold matrix. Can someone please take time out and explain it to me ?
% A1 is the input image
A1max=ordfilt2(A1,512*512,ones(512,512)); %my max value % 512x512 Maximum Filter
A1min=ordfilt2(A1,1,ones(512,512)); %mIN value % 512 X 512 Minimum Filter
A1dif=A1max-A1min;
avg=filter2(fspecial('average',7),A1)';
z=0.9;%%GAMMA
c=0.5;%%ALPHA
[ka, kb]=size(A1);
for i=1:ka
for j=1:kb
if avg(i,j)> c*A1dif(i,j) && (abs(avg(i,j)-A1(i,j))/(avg(i,j)))<(1-c)
if avg(i,j)>=A1(i,j)
TH(i,j)=c*avg(i,j);
else
TH(i,j)=avg(i,j);
end
else
TH(i,j)= avg(i,j)+z*A1dif(i,j);
end
end
end
How does one pick the Gamma and Alpha values?

Respuestas (1)

Image Analyst
Image Analyst el 20 de Feb. de 2015
Editada: Image Analyst el 20 de Feb. de 2015
I'd say it's just by trial and error to see what looks good. You might want to use rangefilt() instead of doing ordfilt twice. Also, you vectorize the loops to speed it up and make it more compact.
Man, that's one weird filter. What's its purpose?
clc;
clear all;
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% A1 is the input image
A1 = imread('cameraman.tif');
% Display the original gray scale image.
subplot(1, 2, 1);
imshow(A1, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
A1max=ordfilt2(A1,512*512,ones(512,512)); %my max value % 512x512 Maximum Filter
A1min=ordfilt2(A1,1,ones(512,512)); %mIN value % 512 X 512 Minimum Filter
A1dif=A1max-A1min;
avg=filter2(fspecial('average',7),A1)';
z=0.9;%%GAMMA
c=0.5;%%ALPHA
[ka, kb]=size(A1);
for i=1:ka
for j=1:kb
if avg(i,j)> c*A1dif(i,j) && (abs(avg(i,j)-A1(i,j))/(avg(i,j)))<(1-c)
if avg(i,j)>=A1(i,j)
TH(i,j)=c*avg(i,j);
else
TH(i,j)=avg(i,j);
end
else
TH(i,j)= avg(i,j)+z*A1dif(i,j);
end
end
end
subplot(1, 2, 2);
imshow(TH, []);
title('TH Image', 'FontSize', fontSize);
It looks like it filters twice, once on the transpose of the image and adds them together. What is this for?
  4 comentarios
Rakshith Nayak
Rakshith Nayak el 24 de Sept. de 2020
how did you get alpha ,gamma and 'average' 7(line 23) values?
Image Analyst
Image Analyst el 24 de Sept. de 2020
Personally, I don't know, and nazneen hasn't been seen here in 5 years.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by