How to concatenate GRAYSCALE and RGB images?

18 Ansichten (letzte 30 Tage)
edusadiq
edusadiq am 30 Okt. 2019
Kommentiert: DGM am 26 Okt. 2022
I'm trying to concatenate a graysacale and rgb image but it shows error.
This is the code
>> A = imread('bird.jpg');
>> B = rgb2gray(A);
>> imshow(A),imshow(B);
>> C = cat(2,A,B);
Error using cat
Dimensions of arrays being concatenated are not consistent.
Can someone help me out?
I want this effect which is shown in given image
Concatenate GRAYSCALE and RGB image in MATLAB.jpg

Akzeptierte Antwort

Sai Bhargav Avula
Sai Bhargav Avula am 30 Okt. 2019
Bearbeitet: Sai Bhargav Avula am 30 Okt. 2019
Hi, If just want to stitch them you can try using the montage() function of matlab.
Hope this helps!
  4 Kommentare
edusadiq
edusadiq am 30 Okt. 2019
Yes, it worked 100%.
DGM
DGM am 26 Okt. 2022
If the goal is to produce a composite image for further processing (or saving) and you want something with the abilities of montage(), you can also use IPT imtile() instead.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

DGM
DGM am 26 Okt. 2022
Alternatively, you can expand the grayscale image. Assuming the images have compatible geometry, they can then be edge-concatenated as normal.
% an RGB image and a mono image
RGB = imread('peppers.png');
I = rgb2gray(RGB);
% expand the single-channel image
Irgb = repmat(I,[1 1 3]);
% concatenate the images
outpict = [Irgb RGB];
imshow(outpict)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by