why can not read images with structures from my folder with different resolution ??

I am reading some images from my folder. I am using structures but If I read from my folder first image all is ok and the FOR statement is ended due to is error message matlab shows:
??? Index exceeds matrix dimensions.
Error in ==> select_part_img at 26
images_part=images_set(1,i); img=imread(images_part.name);
What is problem ? How can I solve this problem ? In my folder are images with different resolution.

 Accepted Answer

Your line
[img_num,no_used]=size(images_set);
is probably incorrect. images_set will be a structure array vector: one of its two dimensions is going to be 1, probably its second dimension, leading to no_used being 1
When "i" is 2, your line
images_part=images_set(1,i);
is going to be incorrect: it is the first dimension that increases. You need
images_part=images_set(i,1);
Better yet, ignore rows vs columns by using
img_num = length(images_set);
and
images_part=images_set(i);

3 Comments

thank you very much. At this moment my code is working.
Could you help me one again ? I have similar problem with my code. Could you help me? I have this code:
function [image_DB,mask_DB_gray]=Pictogram_main(dataInput_folder)
% script for image description
% data_folder=dir(uigetdir('Choose the directory for image searching'));
%%
path(path,dataInput_folder);
images_set=dir([dataInput_folder,'/*.jpg']);
masks_set=dir([dataInput_folder,'/*.bmp']);
%%
[img_num,no_used]=size(images_set);
% image descriptions
%%
for i=1:img_num
image_part=images_set(i,1); image_DB=imread((image_part.name));
mask_part=masks_set(i,1); mask_DB_gray=rgb2gray(imread(mask_part.name));
segment_value=find((imhist(mask_DB_gray))>0)-1;
[segment_num,no_used]=size(segment_value);
subplot(1,3,1); imshow(image_DB)
%%
for j=1:segment_num
mask_segment=uint8(mask_DB_gray==segment_value(j));
mask_segment_RGB(:,:,1)=mask_segment;
mask_segment_RGB(:,:,2)=mask_segment;
mask_segment_RGB(:,:,3)=mask_segment;
image_segment=image_DB.*mask_segment_RGB;
subplot(1,3,2); imshow(mask_segment, [0 1])
subplot(1,3,3); imshow(image_segment)
pause
end
end
If I read the first image all is OK and after that the program read second image but the matlab show this problems message:
??? Subscripted assignment dimension mismatch.
Error in ==> Pictogram_main at 46
mask_segment_RGB(:,:,1)=mask_segment;
What can I do with this please ?
Could you help me one again ? I have similar problem with my code. Could you help me? I have this code:
function [image_DB,mask_DB_gray]=Pictogram_main(dataInput_folder)
% script for image description
% data_folder=dir(uigetdir('Choose the directory for image searching'));
%%
path(path,dataInput_folder);
images_set=dir([dataInput_folder,'/*.jpg']);
masks_set=dir([dataInput_folder,'/*.bmp']);
%%
[img_num,no_used]=size(images_set);
% image descriptions
%%
for i=1:img_num
image_part=images_set(i,1); image_DB=imread((image_part.name));
mask_part=masks_set(i,1); mask_DB_gray=rgb2gray(imread(mask_part.name));
segment_value=find((imhist(mask_DB_gray))>0)-1;
[segment_num,no_used]=size(segment_value);
subplot(1,3,1); imshow(image_DB)
%%
for j=1:segment_num
mask_segment=uint8(mask_DB_gray==segment_value(j));
mask_segment_RGB(:,:,1)=mask_segment;
mask_segment_RGB(:,:,2)=mask_segment;
mask_segment_RGB(:,:,3)=mask_segment;
image_segment=image_DB.*mask_segment_RGB;
subplot(1,3,2); imshow(mask_segment, [0 1])
subplot(1,3,3); imshow(image_segment)
pause
end
end
If I read the first image all is OK and after that the program read second image but the matlab show this problems message:
??? Subscripted assignment dimension mismatch.
Error in ==> Pictogram_main at 46
mask_segment_RGB(:,:,1)=mask_segment;
What can I do with this ?

Sign in to comment.

More Answers (1)

dbstop if error
And inspect the variables at the line in question (line 26)

1 Comment

It is clear but why?? Look at my code:
function [im_part,img_gray,img]=select_part_img(dataInput_folder)
% Author: Fric
% Date: 17.01.2012
% data_folder=dir(uigetdir('Choose the directory for image searching'));
%http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
path(path,dataInput_folder);
images_set=dir([dataInput_folder,'/*.jpg']);
mask_set=dir([dataInput_folder,'/*.bmp']);
%resize images
% [img_num,no_used]=size(images_set);
% for i = 1:img_num
% im_set=images_set(i,:);
% imshow(reshape(im_set,300,300)');
% imresize(im_set,[300,300]);
% figure();
% end
[img_num,no_used]=size(images_set);
for i=1:img_num
images_part=images_set(1,i); img=imread(images_part.name);
mask_part=mask_set(i,1); img_gray=rgb2gray(imread(mask_part.name));
figure(1),subplot(2,2,1); imshow(img);
im_hist=find((imhist(img_gray))>0)-1;
[segment_num,no_used]=size(im_hist);
[r,c]=size(img_gray);
%
for j=1:segment_num
im_part = (img_gray == im_hist(j,1));
figure(1),subplot(2,2,1); imshow(img_gray)
figure(1),subplot(2,2,3); imshow(im_part)
pause
end
end

Sign in to comment.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!