我想从内存中读取一系列大小为256 * 256的灰度图像并存储在一个数组中。后来我想从数组中访问每个图像的各个像素。我怎么能这样做?
答案 0 :(得分:1)
你的意思是:
NumImages = 20;
% reading
for Ind = 1:NumImages
% replace by your read image function
ImgArray(:, :, Ind) = rand(256, 256);
end
% accessing the pixel in place (1, 2) of the 3rd img in array
SinglePixel = ImgArray(1, 2, 3);
答案 1 :(得分:0)
假设您有6个256x256图像,由'IM1.jpg'命名为'IM6.jpg',位于文件夹'C:\ ImagesSeq \'中。现在你想把它们读成Matlab。
IMArray=zeros(256,256,6); % preallocate the memonry for your image array
for i=1:6 % you can replace 6 by any number you need
Filename=sprintf('C:/ImagesSeq/IM%d.jpg',i);
IMArray(:,:,i)=imread(Filename);
end
% you can now accessing the pixel as last answer shows by indexing the Image array
SinglePixel = IMArray(1, 2, 3);
我希望这就是你的意思.... :)