MATLAB: How to add and subtract two color images in matlab

digital image processingimage processingMATLAB

I-G(I);
where I=original image and G(I)=Gaussian filtered version of I.

Best Answer

Hi, Sajina the function imsubtract expects two real, nonsparse, numeric or logical image. Threfore the below syntax is not right.
z = imsubtract(double(X)-double(Y));
Try the code below.
% Read your image here
X = imread('peppers.png');
figure; imshow(X, []); title('Original Color Image');
% Gaussian Filtering
sigma = 5; % Standard deviation of the kernel
Y = imgaussfilt(X, sigma);
figure; imshow(Y, []); title('Gaussian Filtered Image');
Z = imsubtract(X, Y);
N = imadjust(Z, stretchlim(Z));
figure,imshow(N, []), title('Histogram Stretched Subtracted Image');
gaussSub.png
Hope this helps!