# I convolve two images but doesn't work can you help me.

1 view (last 30 days)
Amjad Mushtaq on 21 Apr 2022
Answered: DGM on 22 Apr 2022
% 2nd Assignemnt i get two images of low light and infrared image.
% show the upword images
subplot(3,3,1);imshow(a);title('image A')
subplot(3,3,2);imshow(b);title('image B')
% resize the images of B becouse the size is difference.
re=imresize(b, [471 625])
subplot(3, 3, 3);imshow(re);title('Resize image B')
% add the image ( a ) and resize image.
% multiply the image A and resize image
mult=a.*re
subplot(3, 3, 5);imshow(mult); title('multiplication ')
% subtract A image into resize image.
sub=a-re
subplot(3, 3, 6);imshow(sub); title('subtraction')

DGM on 22 Apr 2022
There is no convolution happening here. You didn't include either image, so I don't know if a mismatch of channels is also causing a problem. For sake of demonstration, I'm just going to feed it an RGB image.
b = fliplr(a);
% show the upword images
subplot(2,3,1);imshow(a);title('image A')
subplot(2,3,2);imshow(b);title('image B')
% resize the images of B becouse the size is difference.
re = imresize(b,[size(a,1) size(a,2)]); % get the actual size from the array instead of assuming a literal
subplot(2, 3, 3)
imshow(re)
title('Resize image B')
% add the image A and resize image.
subplot(2, 3, 4)
title('Addition of image A & Resize')
% multiply the image A and resize image
mult = im2double(a).*im2double(re); % data class makes a difference
subplot(2, 3, 5)
imshow(mult)
title('multiplication ')
% subtract A image into resize image.
sub = a-re;
subplot(2, 3, 6)
imshow(sub)
title('subtraction') Note that multiplication won't work as expected if the images are uint8. Image multiplication relies on the assumption that one of the images is unit scale (i.e. the data range is [0 1]). Multiplying one image with a range of [0 255] with another of range [0 255] will result in an image that's grossly out of range.
In practice, there are other limitations of mixed-class workflow that are going to cause problems when images are either:
1. integer-class and can't be multiplied by arrays of other class
2. not unit-scale
You can certainly work around these limitations as they come up, but the simple way is to do the core operations in floating point and then convert back to integer when done. Using im2double() and im2uint8() will do the conversion and rescaling.
This similar question may be of use:
how do i make an RGB+thermal image? (some blending notes and format considerations)

R2021a

### Community Treasure Hunt

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

Start Hunting!