"Subscripted assignment dimension mismatch" Error

1 次查看(过去 30 天)
Hello,
I am working on a script that was made a few years ago. I had to make some changes to it, and now I can get it to run on certain images, but not on all. When I change the images in my folder to a new set, I get the error:
Subscripted assignment dimension mismatch.
Error in luminance (line 29)
alc(i,1).rgb(:,:,:) = imread(alcJPG(i).name); %now in format [rows columns RGB=1,2,3]
I have included the relevant portion of the code below. I'm not sure why I am only getting this error on some images and not others. Thank you for the help.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%read in alc and nonalc images and convert to RBG with imread
display ('reading alc and nonalc images');
cd(alc_dir);
alcJPG = dir('*.JPG'); %alcohol images
for i = 1:length(alcJPG)
alc(i,1).rgb(:,:,:) = imread(alcJPG(i).name); %now in format [rows columns RGB=1,2,3]
alc(i).hsv = rgb2hsv(alc(i).rgb); %convert to HSV %%%(Hue, Saturation, Value)
alc(i).ycbcr = rgb2ycbcr(alc(i).rgb); %convert to YCbCr %%%(brightness, two color dif signals- Cb and Cr)
alc(i).lab = RGB2Lab(alc(i).rgb); %convert to Lab %%%(Lightness and color-opponent dimenstions-- a and b)
end
cd(nonalc_dir);
nonalcJPG = dir('*.JPG'); %nonalcohol images
for i = 1:length(nonalcJPG)
nonalc(i,1).rgb(:,:,:) = imread(nonalcJPG(i).name); %now in format [rows columns RGB=1,2,3]
nonalc(i).hsv = rgb2hsv(nonalc(i).rgb); %convert to HSV, V = 3 (value)
nonalc(i).ycbcr = rgb2ycbcr(nonalc(i).rgb); %convert to YCbCr, Y = 1 (luminance)
nonalc(i).lab = RGB2Lab(nonalc(i).rgb); %convert to Lab
end
cd(p);
display ('calculating RGB means');
for i = 1:length(nonalc)
%RGB means
alc(i).meanRintensity = mean(mean(alc(i).rgb(:,:,1),2),1);
alc_meanR(i) = alc(i).meanRintensity;
alc(i).meanGintensity = mean(mean(alc(i).rgb(:,:,2),2),1);
alc_meanG(i) = alc(i).meanGintensity;
alc(i).meanBintensity = mean(mean(alc(i).rgb(:,:,3),2),1);
alc_meanB(i) = alc(i).meanBintensity;
nonalc(i).meanRintensity = mean(mean(nonalc(i).rgb(:,:,1),2),1);
nonalc_meanR(i) = nonalc(i).meanRintensity;
nonalc(i).meanGintensity = mean(mean(nonalc(i).rgb(:,:,2),2),1);
nonalc_meanG(i) = nonalc(i).meanGintensity;
nonalc(i).meanBintensity = mean(mean(nonalc(i).rgb(:,:,3),2),1);
nonalc_meanB(i) = nonalc(i).meanBintensity;
%HSV mean (only store V)
alc(i).meanVintensity = mean(mean(alc(i).hsv(:,:,3),2),1);
alc_meanV(i) = alc(i).meanVintensity;
nonalc(i).meanVintensity = mean(mean(nonalc(i).hsv(:,:,3),2),1);
nonalc_meanV(i) = nonalc(i).meanVintensity;
%YCbCr mean (only store Y)
alc(i).meanYintensity = mean(mean(alc(i).ycbcr(:,:,1),2),1);
alc_meanY(i) = alc(i).meanYintensity;
nonalc(i).meanYintensity = mean(mean(nonalc(i).ycbcr(:,:,1),2),1);
nonalc_meanY(i) = nonalc(i).meanYintensity;
%Lab mean (only store L)
alc(i).meanLintensity = mean(mean(alc(i).lab(:,:,1),2),1);
alc_meanL(i) = alc(i).meanLintensity;
nonalc(i).meanLintensity = mean(mean(nonalc(i).lab(:,:,1),2),1);
nonalc_meanL(i) = nonalc(i).meanLintensity;
end
%to apply SHINE to the image need to replace V with Y to change to HSL -
%but SHINE is only useful if we want to match the luminance in the images,
%not just report it
%therefore, let's create a text output with all of these values in order to
%input to spss
out = fopen([export_dir 'luminance_test_4.25a.txt'], 'wt');
fprintf(out,'img, group, meanR, meanG, meanB, meanV, meanY, meanL\n');
for i = 1:length(alcJPG) %%this should be the # of jpgs in folder
display ('alc out');
if length(alcJPG(i).name(1:4)) == 4 %%AT added: if first 4 letters = 4 letters (always will) then....
%if length(alcJPG(i).name) == 6; %%original was basing if on length of
%filename... changed it to work around this
fprintf(out,'%s, alc, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f\n', alcJPG(i).name(:),alc_meanR(i),alc_meanG(i), ...
alc_meanB(i),alc_meanV(i),alc_meanY(i),alc_meanL(i)); %%.name(ratio) here is printing to output the first 2,3,4 letters...WHY?
%%.name(:) prints whole filename
elseif length(alcJPG(i).name) == 7
fprintf(out,'%s, alc, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f\n', alcJPG(i).name(1:3),alc_meanR(i),alc_meanG(i), ...
alc_meanB(i),alc_meanV(i),alc_meanY(i),alc_meanL(i));
elseif length(alcJPG(i).name) == 8
fprintf(out,'%s, alc, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f\n', alcJPG(i).name(1:4),alc_meanR(i),alc_meanG(i), ...
alc_meanB(i),alc_meanV(i),alc_meanY(i),alc_meanL(i));
end
end
for i = 1:length(nonalcJPG)
display ('nonalc out');
if length(nonalcJPG(i).name) == 6
fprintf(out,'%s, nonalc, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f\n', nonalcJPG(i).name(1:2),nonalc_mefclose(out),anR(i),nonalc_meanG(i), ...
nonalc_meanB(i),nonalc_meanV(i),nonalc_meanY(i),nonalc_meanL(i));
elseif length(nonalcJPG(i).name(1:7)) == 7 %%changed ==7 rather than 6 like alc because 6 here has a weird line (mefclose(out))
%elseif length(nonalcJPG(i).name) == 7
fprintf(out,'%s, nonalc, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f\n', nonalcJPG(i).name(:),nonalc_meanR(i),nonalc_meanG(i), ...
nonalc_meanB(i),nonalc_meanV(i),nonalc_meanY(i),nonalc_meanL(i));
elseif length(nonalcJPG(i).name) == 8
fprintf(out,'%s, nonalc, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f, %4.4f\n', nonalcJPG(i).name(1:4),nonalc_meanR(i),nonalc_meanG(i), ...
nonalc_meanB(i),nonalc_meanV(i),nonalc_meanY(i),nonalc_meanL(i));
end
end
  3 个评论
Holly Pothier
Holly Pothier 2018-4-25
Unfortunately I only have access to 2014a. I will try to find a more recent version and run this, thank you.
Walter Roberson
Walter Roberson 2018-4-25
I posted a follow-up there describing what would need to be done for earlier versions.

请先登录,再进行评论。

回答(1 个)

Holly Pothier
Holly Pothier 2018-4-25
Here are some examples of the filenames that work, and do not work:
This type of filename works: 1P_1.jpg, but when I use their resized versions with the filename: 1P_1_RS.jpg I get the error above. This occurs with our two image types/folders.
  15 个评论
Holly Pothier
Holly Pothier 2018-4-25
...that fixed the problem / error. Thank you for your help and all the suggestions.
I will try with all my stimuli and report back.
Thanks again.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by