Azzera filtri
Azzera filtri

Convolution giving decimal point in the result

1 visualizzazione (ultimi 30 giorni)
Hi,
Im trying to learn to look on the result from the kernel after convolution. Even i followed youtube for the double on the data but yet has a problem with the result.
Here is the code and the result, i don't know what else i had to change..
I = imread('C:\\MEKH\\LENA.jpg');
figure, imshow(I);
J=rgb2gray(I);
figure, imshow(J)
J=double(J)
A = [1,1,1;1,1,1;1,1,1]/9;
B = conv2(J,A,'same')
B=double(B)
figure, imshow(B)
Result:
Input
J =
222 208 255 255 253
105 141 82 108 169
121 252 4 1 124
89 124 79 195 227
253 252 196 221 250
B =
75.1111 112.5556 116.5556 124.6667 87.2222
116.5556 154.4444 145.1111 139.0000 101.1111
92.4444 110.7778 109.5556 109.8889 91.5556
121.2222 152.2222 147.1111 144.1111 113.1111
79.7778 110.3333 118.5556 129.7778 99.2222

Risposta accettata

Ameer Hamza
Ameer Hamza il 13 Giu 2020
Modificato: Ameer Hamza il 13 Giu 2020
the output of conv2() is expected to be a fractional number. To use imshow, first convert it to uint8(). There are two alternatives
Convert the output of conv to uint8
I = imread('C:\\MEKH\\LENA.jpg');
figure, imshow(I);
J = rgb2gray(I);
figure, imshow(J)
J = double(J)
A = [1,1,1;1,1,1;1,1,1]/9;
B = conv2(J,A,'same')
B = uint8(B)
figure, imshow(B)
Or, use im2double() to convert the original image to double datatype
I = im2double(imread('C:\\MEKH\\LENA.jpg'));
figure, imshow(I);
J=rgb2gray(I);
figure, imshow(J)
A = [1,1,1;1,1,1;1,1,1]/9;
B = conv2(J,A,'same')
figure, imshow(B)
  2 Commenti
Zamani Md Sani
Zamani Md Sani il 13 Giu 2020
thanks for sharing your knowledge to me.. just a month learning matlab .. thanks

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by