www.pudn.com > watermarking-with-Hus-moments.rar > namayesh7nahieh.m, change:2015-06-28,size:1727b


function namayesh7nahieh(f,q)  
I=f; 
I=imresize(I,[400 400]); 
t = graythresh(I);  
BW = im2bw(I, t);  
 
% Step 2: Leave just "big" components on binary image 
[L, num] = bwlabel(BW);  
stats = regionprops(L, 'Area', 'PixelIdxList'); 
area_vector = [stats(:).Area]; 
area_vector = sort(area_vector); 
threshold_pos = floor(num * 0.98); 
threshold = area_vector(threshold_pos); 
 
for i=1:num 
    if(stats(i).Area < threshold) 
        BW(stats(i).PixelIdxList) = false; 
    end 
end 
 
% Step 3: Dilate image with a circle of small radius 
str = strel('disk', 7);  
BW = imdilate(BW, str);  
 
% Step 4: Take component with biggest area as the circle 
L = bwlabel(BW);  
stats = regionprops(L, 'Area', 'BoundingBox', 'Centroid', 'EquivDiameter'); 
area_vector = [stats(:).Area]; 
[max_value, max_idx] = max(area_vector); 
soi = stats(max_idx); 
 
% Set output variable 
circle = imcrop(I, soi.BoundingBox); 
 
% Display results 
% radius = soi.EquivDiameter/2; 
radius = 80; 
N = 1000; 
theta = linspace(0, 2*pi, N); 
rho = ones(1, N) * radius; 
[X,Y] = pol2cart(theta, rho); 
X1 = q(1) - X; 
Y1 = q(1) - Y; 
X2 = q(2) - X; 
Y2 = q(2) - Y; 
X3 = q(3) - X; 
Y3 = q(3) - Y; 
X4 = q(4) - X; 
Y4 = q(4) - Y; 
X5 = q(5) - X; 
Y5 = q(5) - Y; 
X6 = q(6) - X; 
Y6 = q(6) - Y; 
X7 = q(7) - X; 
Y7 = q(7) - Y; 
figure;  
subplot(1,2,1); 
imshow(I); 
hold on; 
plot(X1, Y1, '-r', 'LineWidth', 2); 
hold on; 
plot(X2, Y2, '-r', 'LineWidth', 2); 
hold on; 
plot(X3, Y3, '-r', 'LineWidth', 2);hold on; 
plot(X4, Y4, '-r', 'LineWidth', 2);hold on; 
plot(X5, Y5, '-r', 'LineWidth', 2);hold on; 
plot(X6, Y6, '-r', 'LineWidth', 2);hold on; 
plot(X7, Y7, '-r', 'LineWidth', 2); 
 
title('Original graycale image + circles', 'FontSize', 12)