Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I was wondering if anyone could look at this code. I'm trying to do a 3x3 gaussian kernel without using any matlab built-in functions. (Yes I am aware of all the built in functions of gaussian and convolution ie fspecial) the result gives me a white image instead. not sure what's the problem with it.
Thanks.

 clc;

close all;

clear all;





img=imread('image.jpg');

figure,imshow(img);




img2=zeros(size(img)+2);

newImg=zeros(size(img));



for rgb=1:3

        for x=1:size(img,1)

            for y=1:size(img,2)

                img2(x+1,y+1,rgb)=img(x,y,rgb);

            end

        end

end


    for i= 1:size(img2,1)-2

        for j=1:size(img2,2)-2

            window=zeros(9,1);

            inc=1;

            for x=1:3

                for y=1:3

                    window(inc)=img2(i+x-1,j+y-1,rgb);

                    inc=inc+1;

                end

            end


              kernel=[1;2;1;2;4;2;1;2;1];

%             kernel=[0;1;0;1;-4;1;0;1;0];


            med=window.*kernel;

            disp(med);

            med=sum(med);

            med=floor(med);



            newImg(i,j,:)=med;



        end

    end



newImg=uint8(newImg);

figure,imshow(newImg);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900