Convolution giving decimal point in the result

1 vue (au cours des 30 derniers jours)
Zamani Md Sani
Zamani Md Sani le 13 Juin 2020
Commenté : Ameer Hamza le 13 Juin 2020
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

Réponse acceptée

Ameer Hamza
Ameer Hamza le 13 Juin 2020
Modifié(e) : Ameer Hamza le 13 Juin 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 commentaires
Zamani Md Sani
Zamani Md Sani le 13 Juin 2020
thanks for sharing your knowledge to me.. just a month learning matlab .. thanks
Ameer Hamza
Ameer Hamza le 13 Juin 2020
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by