How do I resize an image displayed using imagesc() in a figure?

조회 수: 104 (최근 30일)
Aaron Elliott
Aaron Elliott 2020년 11월 2일
답변: yanqi liu 2021년 2월 1일
Hi,
How do I resize the images below so they are all the one size?
function [Edges, Ihor, Iver] = edgeExtraction(Iin,B1,B2)
Iin = im2double(Iin);
% Iver = Iin .* B1;
% Ihor = Iin .* B2;
% Edges = edge(Iin);
Ihor = conv2(Iin, B2);
Iver = conv2(Iin, B1);
Edges = sqrt((Iver.^2) + (Ihor.^2));
subplot(1,4,2), imagesc(Ihor), title('Horizontal')
subplot(1,4,3), imagesc(Iver), title('Vertical')
subplot(1,4,4), imagesc(Edges), title('Edges')
end
clear all
close all
boatN = imread('boatnois.jpg');
B1 = [-1 0 1; -1 0 1; -1 0 1];
B2 = [-1 -1 -1; 0 0 0; 1 1 1];
figure(1)
subplot(1,4,1), imshow(boatN), title('Boat');
edgeExtraction(boatN, B1, B2)

답변 (3개)

Gouri Chennuru
Gouri Chennuru 2020년 11월 5일
Hi Aaron,
As a workaround, you can first resize all the images using MATLAB function “imresize” to a definite size and then add them into the figure using a subplot and "imagesc".
Hope this Helps!

Walter Roberson
Walter Roberson 2020년 11월 5일
imagesc() accepts properties 'XData' and 'YData', or you can pass x and y coordinates as the first two parameters to imagesc()
The x you pass should be a vector of two values, the first is the data x coordinate for the center of the lower-left pixel, and the second is the data x coordinate for the center of the upper-right pixel. Likewise for the y, and again the values are data coordinates for centers.
This does not resize the image in the sense of changing the number of pixels in the image array: this instead tells MATLAB where to draw the image, with the image being visually expanded or compacted as necessary in order to fit those data coordinates.

yanqi liu
yanqi liu 2021년 2월 1일
clc; clear all; close all;
boatN = imread('football.jpg');
B1 = [-1 0 1; -1 0 1; -1 0 1];
B2 = [-1 -1 -1; 0 0 0; 1 1 1];
figure(1)
subplot(1,4,1), imshow(boatN), title('Boat');
edgeExtraction(boatN, B1, B2)
function [Edges, Ihor, Iver] = edgeExtraction(Iin,B1,B2)
if ndims(Iin) > 2
Iin = rgb2gray(Iin);
end
Iin = im2double(Iin);
% Iver = Iin .* B1;
% Ihor = Iin .* B2;
% Edges = edge(Iin);
Ihor = conv2(Iin, B2);
Iver = conv2(Iin, B1);
Edges = sqrt((Iver.^2) + (Ihor.^2));
subplot(1,4,2), imagesc(Ihor), title('Horizontal')
axis equal
axis tight
subplot(1,4,3), imagesc(Iver), title('Vertical')
axis equal
axis tight
subplot(1,4,4), imagesc(Edges), title('Edges')
axis equal
axis tight
end

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by