How do I subplot figures and Title Figures

조회 수: 6(최근 30일)
Cameron Kreevich
Cameron Kreevich 2021년 12월 6일
댓글: Yongjian Feng 2021년 12월 7일
I have a code that is averaging 20 slightly different frames, all in all the code produces 25 total frames and is very messy when ran. I would like to somehow subplpot the figures on one plot so it is more organized. I would like to show figures 1,5,10,15,20,21,22,23,24,25 and the rest I do not want to show up when I run the code and I would also like them to be plotted on one plot or two as well as add a title to the individual figures. If someone could help me out it would be greatly appricieated.
For example something that kind of looks like this:
close all;
clear all;
clc;
load('undergraduate_data.mat');
for index = 1:1:size(photoshift,3);
figure;
imshow(photoshift(:, :, index), []);
grid on;
daspect([1 1 1]);
end
fixed = photoshift(:, :, 1);%refrence image
figure('Name', 'Fixed Image -Frame 1');
imshow(fixed, []);
%creating an unregistered image by distorting
theta =165;
rot = [cosd(theta) sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1];
sc = 2.3;
scale = [sc 0 0; 0 sc 0; 0 0 1];
sh = 0.5;
shear = [1 sh 0; 0 1 0; 0 0 1];
tform = affine2d(shear*scale*rot);
moving = imwarp(fixed,tform);
figure('Name', 'original');
imshow(fixed, []);
figure('Name', 'Transformation');
imshow(moving,[]);
%estimating registration required to bring images in allignment
tformEstimate=imregcorr(moving,fixed);
Rfixed = imref2d(size(fixed));
movingReg = imwarp(moving,tformEstimate, 'OutputView', Rfixed);
figure;%figure24
imshowpair(fixed,movingReg,'montage');
%Final Registration
[optimizer, metric] = imregconfig('monomodal');
movingRegistered = imregister(moving,fixed,'affine',optimizer,metric,'InitialTransformation',tformEstimate);
A = figure('Name', 'Averaging');
imshowpair(fixed, movingRegistered,'Scaling','joint');
save Averaging.mat A

답변(3개)

Yongjian Feng
Yongjian Feng 2021년 12월 6일
Try this:
subplot(2, 3, 1); % there are 2x3 images, this is the first one
imshow('the_first_image.png'); % show first
title('Original');
subplot(2, 3, 2); % the second image
imshow('the_second_image.png');
title('Frame 1');
.....
  댓글 수: 2
Yongjian Feng
Yongjian Feng 2021년 12월 7일
No. imshow can handle other graphic formats.

댓글을 달려면 로그인하십시오.


David Hill
David Hill 2021년 12월 6일
Look at subplot() command.
subplot(1,2,1); imshow(image1);
subplot(1,2,2); imshow(image2);

yanqi liu
yanqi liu 2021년 12월 7일
yes,sir,may be use montage or subplot,such as
close all;
clear all;
clc;
% load('undergraduate_data.mat');
a = imread('cameraman.tif');
b = imread('rice.png');
photoshift(:,:,1) = a;
photoshift(:,:,2) = b;
figure; montage(photoshift, 'BackgroundColor', 'w', 'BorderSize', [2 2]);
fixed = photoshift(:, :, 1);%refrence image
figure('Name', 'Fixed Image -Frame 1');
subplot(1, 5, 1); imshow(fixed, []);
%creating an unregistered image by distorting
theta =165;
rot = [cosd(theta) sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1];
sc = 2.3;
scale = [sc 0 0; 0 sc 0; 0 0 1];
sh = 0.5;
shear = [1 sh 0; 0 1 0; 0 0 1];
tform = affine2d(shear*scale*rot);
moving = imwarp(fixed,tform);
subplot(1, 5, 2); imshow(fixed, []);
subplot(1, 5, 3); imshow(moving,[]);
%estimating registration required to bring images in allignment
tformEstimate=imregcorr(moving,fixed);
Rfixed = imref2d(size(fixed));
movingReg = imwarp(moving,tformEstimate, 'OutputView', Rfixed);
subplot(1, 5, 4);
imshowpair(fixed,movingReg,'montage');
%Final Registration
[optimizer, metric] = imregconfig('monomodal');
movingRegistered = imregister(moving,fixed,'affine',optimizer,metric,'InitialTransformation',tformEstimate);
subplot(1, 5, 5);
imshowpair(fixed, movingRegistered,'Scaling','joint');

Community Treasure Hunt

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

Start Hunting!

Translated by