필터 지우기
필터 지우기

Error in matrix assignment

조회 수: 1 (최근 30일)
Anthony Knighton
Anthony Knighton 2022년 5월 19일
답변: Chunru 2022년 5월 20일
I am attempting to create a MXNXP image stack, where M and N are the vertical and horizontal dimensions, and P is a third dimension that represents the number of images in the stack. For one particular set of images, I keep getting an error message that says "Unable to perform assignment because the size of the left side is 128-by-128 and the size of the right side is 256-by-256." Not sure what this means, but it looks like m and n are getting multiplied by 2.. Do not know why it would be doing this. This same code works for other sets of images. Here is the code:
function num_images = img_2_stack(path)
% path = '/path/to/image/directory'
% create image stack
dir_info = dir(fullfile(path, '*.png'));
num_images = numel(dir_info)
m = 128; % vertical pixels
n = 128; % horizontal pixels
img_stack = zeros(m,n,num_images); % initialize image stack
for i = 1:num_images
fn = dir_info(i).name;
img = imread(fullfile(path, fn));
img_stack(:,:,i) = img;
end
end

채택된 답변

Chunru
Chunru 2022년 5월 20일
The image from the file "img" has a size of 256-by-256. However, you have defined the img_stack with size of 128-by-128-by-#of_images. So that you can not do the assignment operation "img_stack(:,:,i) = img" due to different sizes. You can either change m, n to be 256 (assuming all images have size of 256-by-256) or resize the image to be 128-by-128. "doc imresize" for more info.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by