Filter löschen
Filter löschen

How to convert two rgb images into grayscale? and then subtract ?

2 Ansichten (letzte 30 Tage)
swati mane
swati mane am 18 Mär. 2019
Beantwortet: Image Analyst am 19 Jun. 2021
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 Kommentare
Jan
Jan am 19 Mär. 2019
@swati mane: Does this comment concern my answer? Is your problem solved?
swati mane
swati mane am 19 Mär. 2019
Hello sir,
My problem resolved. thank you!!!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 18 Mär. 2019
img1 = imread('Image1.jpg');
img2 = imread('Image2.jpg');
D = rgb2gray(img1) - rgb2gray(img2)

Weitere Antworten (1)

Image Analyst
Image Analyst am 19 Jun. 2021
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.

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by