0
I = imread ("lena.jpg");
%imshow(I);
K = I;
C = conv2(I, K);
imshow(C);

I am expecting something like the following as indicated in this link.

enter image description here

But, my octave output is blank:

enter image description here

What could be the possible reason?

And, how can I obtain the expected output?

user366312
  • 16,949
  • 65
  • 235
  • 452
  • Possible duplicate of [Imshow and imwrite showing blank image in matlab](https://stackoverflow.com/questions/19978924/imshow-and-imwrite-showing-blank-image-in-matlab) – Cris Luengo Jul 10 '18 at 14:01
  • Hum... maybe this one is better as a duplicate: https://stackoverflow.com/questions/33985585/why-am-i-getting-a-blank-image-as-my-output – Cris Luengo Jul 10 '18 at 14:02

1 Answers1

3

imshow() expect values between [0-255]. After your convolution all your value are way above 255. So of course when you use imshow(C), matlab/octave do a type conversion using uint8(). All your value equal 255 and the result is a white image. (0 = black, 255 = white).

You also should take into account severals things:

  1. add the option 'same' to your convolution to preserve the original size of your image: conv2(I,K,'same')

  2. If you only apply the convolution like that, you will obtain a strong border effect, because the central values of your image will be multiplied more time than the values in the border of your image. You should add a compensation matrix:

    border_compensation = conv2(ones(size(K)),ones(size(K)),'same') C = conv2(I,K,'same')./border_compensation

  3. Normalize the final result (Don't take into account the point 2. if you really want the kind of output that you pointed out in your question)

    C = uint8(C/max(C(:))*255)

obchardon
  • 10,614
  • 1
  • 17
  • 33