How to display two images into one figure without blocking each other?

Dear all,
I have two images in jpg format. I would like to these two images display in one figure lay on each other and without blocking each other. Is it possible?
I attach these two images. Thank you for your answers.

Answers (1)

Yes, just stitch them together
wideImage = [image1, image2]; % Have the same number of rows.
or else use imfuse() or imshowpair(). Or put them into separate axes.

5 Comments

I tried this:
fontSize = 15;
baseFileName = 'thorax-mdl.jpg';
baseFileName_test = 'test_okoli.jpg'
folder = pwd
fullFileName = fullfile(folder, baseFileName);
fullFileName_test = fullfile(folder, baseFileName_test);
% Načtení obrazu.
grayImage = imread(fullFileName);
grayImage_test = imread(fullFileName_test);
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage = grayImage(:, :, 2); % zelený kanál
end
eq_grayImage = histeq(grayImage);%ekvalizace pomocí histogramu obrazu
[rows, columns, numberOfColorChannels] = size(grayImage_pater);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage_pater = grayImage_pater(:, :, 2); % zelený kanál
grayImage_pater(425:end, :) = 0;
end
eq_grayImage_pater = histeq(grayImage_pater);%ekvalizace pomocí histogramu obrazu
% Zobrazení obrazu.
figure(1)
wideImage = [grayImage, grayImage_test];
But I have this error:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in DO_teorie (line 615)
wideImage = [grayImage, grayImage_test];
If they aren't the same number of rows and the same number of color channels, you can't stitch them side by side. They can only vary in the number of columns.
You can stitch top and bottom if they have the same number of rows and color channels like this:
tallImage = [image1; image2];
If one is color and one grayscale, you must convert the grayscale one to color like this:
rgbImage = cat(3, grayImage, grayImage, grayImage);
For a really flexible stitching program see Stitch: http://www.mathworks.com/matlabcentral/fileexchange/25797-stitch
Now, I don´t deal this problem, but I have this figure:
but I would like to have this image:
This is my code:
fontSize = 15;
% baseFileName = '110.jpg';
baseFileName = 'thorax-mdl.jpg';
folder = pwd
fullFileName = fullfile(folder, baseFileName);
% Načtení obrazu.
grayImage = imread(fullFileName);
grayImage_pater = imread (fullFileName);
% Dimenze obrazu.
% numberOfColorBands by měl být = 1.
% ***
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage = grayImage(:, :, 2); % zelený kanál
end
eq_grayImage = histeq(grayImage);%ekvalizace pomocí histogramu obrazu
[rows, columns, numberOfColorChannels] = size(grayImage_pater);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage_pater = grayImage_pater(:, :, 2); % zelený kanál
grayImage_pater(425:end, :) = 0;
end
eq_grayImage_pater = histeq(grayImage_pater);
thresholdValue = 170;
binaryImage = grayImage < thresholdValue;
% Odstranění okolí.
binaryImage = imclearborder(binaryImage);
% Vyplnění otvorů.
binaryImage = imfill(binaryImage, 'holes');
se = strel('line',5,100);
%binaryImage= imdilate(binaryImage,se);
% Práh pro vytvoření binárního obrazu páteře.
bodyMask = grayImage > 128;
% Get rid of white surround.
bodyMask = imclearborder(bodyMask);
% Extract the largest blob only.
bodyMask = bwareafilt(bodyMask, 1);
binaryImage_pater = bodyMask & (grayImage > 220);
% Fill holes.
binaryImage_pater= imfill(binaryImage_pater, 'holes');
binaryImage_pater = bwareaopen(binaryImage_pater,197);
%Find areas.
labeledImage = bwlabel(binaryImage_pater);
se = strel('line',5,100);
%binaryImage_pater= imdilate(binaryImage_pater,se);
%Práh pro vytvoření binárního obrazu okolí
thresholdValue = 180;
binaryImage_okoli = eq_grayImage > thresholdValue;
% Odstranění okolí.
binaryImage_okoli = imclearborder(binaryImage_okoli);
% Vyplnění otvorů.
binaryImage_okoli = imfill(binaryImage_okoli, 'holes');
% Vymazání menších otvorů.
binaryImage_okoli = bwareaopen(binaryImage_okoli, 750);
se = strel('line',5,100);
Npts1 = 20; % počet bodů interpolovaných hranic
Ncomps = 20; % počet fourierových komponentů
shape.thorax=Model(binaryImage_okoli,Ncomps,100);
figure()
tmp=shape.thorax{1};
se = strel('square',5);
erodedBW = imerode(binaryImage_okoli,se);
% erodedBW_plice = imerode(handles.binaryImage,se);
shape.thorax=Model(erodedBW,Ncomps ,30);
tmp = shape.thorax{1};
plot(tmp(:,2), tmp(:,1), 'o-b')
Can you advice me, how transform this curve?
Try
ax = gca; % Get handle to current/last used axes control.
ax.YDir = 'reverse'; % Flip it top to bottom.
Thank you for your answer, I already figured out different way.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

on 23 Apr 2017

Commented:

on 24 Apr 2017

Community Treasure Hunt

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

Start Hunting!