Какая-то ошибка в коде адаптивного медианного фильтра

%% Adaptive Median Filtering - The Code

ip1 = imread ('lena.gif');                  %% Undistorted image
ip = imnoise (ip1,'salt & pepper',0.25);    %% Image corrupted with 'Salt and Pepper Noise'

ip_median_filt1 = medfilt2(ip);             %% Apply median filter to noisy image with window dimensions of 3x3 pixels
ip_median_filt2 = medfilt2(ip,[4,4]);       %% Apply median filter to noisy image with window dimensions of 4x4 pixels
figure(1), clf;
subplot (2, 1, 1), imshow (ip, []);
subplot (2, 1, 2), imshow (ip_median_filt1, []);

%% We now proceed with the adaptive median filtering of the noisy image and 
%% prove that the results are better than those of the standard median filter 
%% shown above

%% Packing zeros around the edge pixels of the noisy input image so as to 
%% allow the facilitate the processing of edge-pixels of the image

ip_edge = zeros (212,276);

ip_convert = double (ip);

%%%%%%%%%% there seems to be error on the following line
ip_edge (11:202, 11:266) = ip_edge (11:202, 11:266) + ip_convert;

smax=9;

for i=11:202
    for j=11:266
        sx=3;
        sy=3;
        while ((sx<=smax) && (sy<=smax))
            ip_edge_min = ip_edge (i, j);
            ip_edge_max = ip_edge (i, j);
            ip_edge_median = median(median(ip_edge((i-floor(sx/2)):(i+floor(sx/2)),(j-floor(sy/2)):(j+floor(sy/2)))));
            for k= (i-floor (sx/2)) :( i+floor (sx/2))
                for l= (j-floor (sy/2)) :( j+floor (sy/2))
                    if ip_edge (k, l) < ip_edge_min
                        ip_edge_min = ip_edge (k, l);
                    end 
                    if ip_edge (k, l) > ip_edge_max
                        ip_edge_max = ip_edge (k, l);
                    end 
                End 
            end 
            A = ip_edge_median - ip_edge_min;
            B = ip_edge_median - ip_edge_max;
            if (A>0) && (B<0)
                C = ip_edge (i, j) - ip_edge_min;
                D = ip_edge (I) - ip_edge_max;
                if (C>0) && (D<0)
                    pledge (i, j) = ip_edge (i, j);
                    break
                else
                    ip_edge (i, j) = ip_edge_median;
                    break
                end 
            else 
                sx=sx+2;
                sy=sy+2;
                if (sx>smax) && (sy>smax)
                    ip_edge(i,j) = ip_edge(i,j);
                end 
            end
        end 
    end 
  end 
end


figure(2), clf;
imshow(ip_edge,[]);

Я получаю ошибку в строке с %%%%%%%%%%:

??? Ошибка при использовании ==> plus Размеры матрицы должны совпадать. Ошибка в ==> adaptive at 22 ip_edge (11:202, 11:266) = ip_edge (11:202, 11:266) + ip_convert;

0
задан gary 11 March 2012 в 17:31
поделиться