フィルターのクリア

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 Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by