How to convert two rgb images into grayscale? and then subtract ?
1 次查看(过去 30 天)
显示 更早的评论
I have two images in jpg format(one as reference image and other is captured image) . I want to convert them to grayscale and want to subtract them. How to do this?
Thanks in Advance.
3 个评论
采纳的回答
Jan
2019-3-18
img1 = imread('Image1.jpg');
img2 = imread('Image2.jpg');
D = rgb2gray(img1) - rgb2gray(img2)
更多回答(1 个)
Image Analyst
2021-6-19
If you don't want negative numbers clipped to zero you can cast to double before subtracting
image1 = imread('Image1.jpg');
image2 = imread('Image2.jpg');
diffImage = double(rgb2gray(image1)) - double(rgb2gray(image2));
imshow(diffImage, []); % Make sure you use []
If you just want the absolute value of the difference, use imabsdiff():
diffImage = imabsdiff(image1, image2);
No need to cast to double in that case.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!