MATLAB: How to view a convolved image in matlab

conv2difference of gaussiansdog filterImage Processing Toolbox

I am currently working on a project where I need to convolve two images grayscale images (0-255 range).I am using conv2() command but the output image matrix is having very high intensity value (292643 and above). I have tried normalizing and then convoluting but that did not work. Here is the code and the image I used.
clc;
clear all;
close all;
image=imread('du5.jpg');
figure(),imshow(image);
grayimage= rgb2gray(image);
im=grayimage;
k=imerode(im,strel('disk',1));
x=imdilate(k,strel('disk',1));
figure(),imshow(x);
k = 1000;
st=std2(x);
sigma1 = st/10;
sigma2 =sigma1*k;
h1 = fspecial('gaussian', [3,3], sigma1);
h2 = fspecial('gaussian', [9,9], sigma2);
gauss1 = imfilter(x,h1,'replicate');
gauss2 = imfilter(x,h2,'replicate');
dogImg = gauss1 - gauss2;
i=conv2(dogImg,im);

Best Answer

The whole algorithm makes no sense. So you're getting the spatial spread of the Gaussian from the standard deviation of the intensity??? One is a distance and the other is a gray level. That is nonsense. They're different units! I see no justification for using an intensity to set a spatial parameter for finding edges.
Next, you convolve the Gaussian with the image using imfilter(). Okay, that's fine. And then you subtract them to get the dog filtered image. Okay, again that's fine. If you just wanted an edge detection image, you should be done now. But to then convolve the filtered image with the original??? What's the logic behind that? Even if you did, you'd end up with an output image 4 times the size of your original images. What are you trying to achieve?
You start off by doing a morphological opening (erosion followed by dilation, which could be done in one step by imopen()). Why? This will essentially expand small dark blobs. Why do you want to do that?
So for multiple reasons I think you need to rethink what you're trying to do.