Adaptive Threshold for Segmentation
이전 댓글 표시
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?
답변 (1개)
Image Analyst
2015년 2월 20일
편집: Image Analyst
2015년 2월 20일
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
nazneen
2015년 2월 20일
Image Analyst
2015년 2월 20일
The vectorized code is attached below the image.

Rakshith Nayak
2020년 9월 24일
how did you get alpha ,gamma and 'average' 7(line 23) values?
Image Analyst
2020년 9월 24일
Personally, I don't know, and nazneen hasn't been seen here in 5 years.
카테고리
도움말 센터 및 File Exchange에서 Image Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!