Effacer les filtres
Effacer les filtres

I wrote a small filter bank with 8 3x3 filters in 8 different orientations, and inside of each filter, there is a valuable v, v is decided by the magnitude of that pixel in the image to be convolved. here are my filter bank function and main program

2 vues (au cours des 30 derniers jours)

I wrote a small filter bank with 8 3x3 filters in 8 different orientations, and inside of each filter, there is a valuable v, v is decided by the magnitude of that pixel in the image to be convolved.I want to filter the image by the 8 filters for 8 times, but the values of the each kernel will change depend on the pixel that it convolves. here are my filter bank function and main program. but when i want to call my filter bank function, matlab shows" Undefined function or variable 'v'.Error in afod (line 24)" could you please help me to find out my fault? function FB = FB(v)

FB = zeros(3,3,8);

FB(:,:,1)=[(v*v-v)/2 0 0;0 -v 0;0 0 1];

FB(:,:,2)=[0 0 (v*v-v)/2;0 -v 0;1 0 0];

FB(:,:,3)=[0 0 0;1 -v (v*v-v)/2;0 0 0];

FB(:,:,4)=[0 0 0;(v*v-v)/2 -v 1;0 0 0];

FB(:,:,5)=[1 0 0;0 -v 0;0 0 (v*v-v)/2];

FB(:,:,6)=[0 0 1;0 -v 0;(v*v-v)/2 0 0];

FB(:,:,7)=[0 1 0;0 -v 0;0 (v*v-v)/2 0];

FB(:,:,8)=[0 (v*v-v)/2 0;0 -v 0;0 1 0];

end

main program:

% read into one image

I=im2double(imread('pout.tif'));

[r,c]=size(I);

%get the minimum & maxmum gray value of image

minI=min(I(:));

maxI=max(I(:));

%expand the image

Rep=zeros(r+4,c+4);

       for x=3:3+r-1
           for y=3:3+c-1
               Rep(x,y)=I(x-3+1,y-3+1);
           end
       end

% get gradient magnitude array for this expanded image

G=imgradient(Rep);

% get the mean value of gradient magnitude of this image (find peak value)

peak=mean2(G);

% define lowest threshold a and higest threshold b

minGI=min(min(G));

maxGI=max(max(G));

a=(peak+minGI)/2;

b=(peak+maxGI)/2;

%call function FB

FB = FB(v);

for f=1:8

    h=rot90(FB(:,:,f),2);
%decide V for each pixel, and convolve adaptive kernel one pixel by one
%pixel
    for x=1:r+2
       for y=1:c+2
% get gradient magnitude for each pixel 
        gradientM=G(x+1,y+1);
        if gradientM<=a
                v=0.1;         
    elseif (a<=gradientM)&&(gradientM<=b)
        v=(((gradientM-minI)/(maxI-minI))*0.7)+0.1; 
            else
        v=0.9;
        end
        for i=1:3
            for j=1:3
                B(x,y)=B(x,y)+(Rep(x+j-1,y+i-1)*h(i,j));
            end
        end
    end
end
end
imshow(B)

Réponses (0)

Catégories

En savoir plus sur Filter Banks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by