MATLAB: Can i subtract 1 image from another by imsubtract()? i am having some errors in this case.

Image Processing Toolboximsubtract()subtracting images

i have generated 2 images, one by sobel operator and 1 by 1×2 operator. now i am trying to subtract the 1×2 operator applied image from sobel operator applied image. i used imsubtract() but it is not displaying the subtracted image. it is giving errors. can we use imsubtract() to only subtract arrays or we can also use it for subtractng images? please let me know.
grayImage= rgb2gray(rgbImage);
size(grayImage);
BW = edge(grayImage,'sobel',0.006);
filteredImage = conv2(double(grayImage), [-1 1], 'same');
subtractedImage = imsubtract(BW,filteredImage);
imshow(subtractedImage);
drawnow();

Best Answer

The values are likely very small for the 1x2 filter - like 0-20 or so. And the Sobel thresholded edge image has values of only 0 and 1. So subtracting almost anything at all from that (except subtracting zero) will clip to zero. So your image is most likely all zeros and displays as black. There may - slight chance - be some pixels that have a value of 1 and you can see those if they exist with the [] option to imshow():
imshow(subtractedImage, []);
But most likely there are no such 1 pixels. But the bigger question is why you are even doing this strange operation in the first place. I can see no theoretical reason why you'd want this subtraction in your algorithm - it's just worthless. Share your thought process so I can see if it makes sense or if what you want to do is better accomplished in some other way that does make sense.