0

I am using conv2 to perform convolution on a gray image. conv2 was returning a floating value so I performed floor operation on it.

The input image is:

InputImage

The code:

clc;
clear all;
close all;
img = imread("balloonGrayNoisy.jpg");
z = ones(3, 3);
newImg = floor( conv2(img, z/9) );

for i = 1:size(newImg, 1)
  for j = 1: size(newImg, 2)
    if(newImg(i,j) > 255)
      disp(newImg(i, j))
    endif
  endfor
endfor

imshow(newImg)

Where img is the image read. When I output the newImg, It shows a blank image:

OutputImage

The loop is to ensure the values are in range. Inface, they are, but I don't know why am I not getting the output.

darkexodus
  • 147
  • 1
  • 14
  • Instead of flooring your image, cast it to `uint8`. Type `double` images are expected to have a range `[0..1]` – beaker Jun 23 '20 at 14:46
  • I am new to this field, but I think for b/w images the pixel intensity should be from 0..255. – darkexodus Jun 23 '20 at 14:48
  • b/w image (1bit) in Matlab/Octave is logical type. – Alex Alex Jun 23 '20 at 14:50
  • Grayscale images can either be `uint8` with a range `[0..255]` or a floating-point type with range `[0..1)`. – beaker Jun 23 '20 at 14:51
  • Sorry for the problem caused. The image is grey and not b/w. I will update the post. – darkexodus Jun 23 '20 at 14:52
  • What should I do now? I am still not getting the output. – darkexodus Jun 23 '20 at 14:58
  • If you've made the suggested changes and they still didn't work for you, you should post a [mre] including your input image and the minimal code required to reproduce your problem. Please note that since there more than 2 people commenting, you'll need to tag the person you're responding to (like @beaker) in order for them to be notified. – beaker Jun 23 '20 at 15:23
  • @beaker I had made the necessary changes. – darkexodus Jun 23 '20 at 16:09
  • 1
    So, you didn't try what I suggested. If I run your code, I get a white image. If I change the last line to `imshow(uint8(newImg))`, I get the expected image. – beaker Jun 23 '20 at 16:17
  • @beaker No. I tried it , but I was running from cmd. The code I used was newImg = unit8( conv2(img, z/9) ); I didn't tried the way you did. Anyway, Thanks for your help. – darkexodus Jun 23 '20 at 16:25
  • That way worked for me as well. Don't know why it didn't for you. – beaker Jun 23 '20 at 16:33
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/216516/discussion-between-neel-rayal-and-beaker). – darkexodus Jun 23 '20 at 16:44

0 Answers0