Why do I get the error message "Subscripted assignment dimension mismatch"?

조회 수: 2 (최근 30일)
Subscripted assignment dimension mismatch.
Error in L1SR (line 144)
hIm(1:3, :) = bhIm(1:3, :);
Error in yima (line 60)
ReconIm = L1SR(lowIm, zooming, patch_size, overlap, Dh, Dl, lambda, regres);
Error in Research_Experiment (line 248)
res{2} = {yima(low{1}, upscaling)};
The highlighted Line (144) to Line (148) has these on code
hIm(1:3, :) = bhIm(1:3, :);
hIm(:, 1:3) = bhIm(:, 1:3);
hIm(end-2:end, :) = bhIm(end-2:end, :);
hIm(:, end-2:end) = bhIm(:, end-2:end);
Why do I have these errors ??
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2018년 11월 22일
You have
[lhg, lwd] = size(lIm);
hhg = lhg*zooming;
hwd = lwd*zooming;
[...]
hIm = zeros([hhg, hwd]);
Assuming that a grayscale image was passed in, the size of lIm will be multiplied by zooming (which is not certain to be an integer by the way) and the result is used to construct hIm . Imagine that lIm is 256 x 256 and that zooming is set to 2, then 256*2 by 256*2 would give a hIm of 512 by 512.
You also have
bhIm = imresize(lIm, 3, 'bicubic');
If the original image lIm were 256 x 256 then the result of bhIm would be 768 x 768.
Now you do
hIm(1:3, :) = bhIm(1:3, :);
Left hand side variable would be 512 x 512, right hand side variable would be 768 x 768. You select three rows and all of the columns of the left hand side as the destination, so that would be 3 x 512 as the destination. The source is three rows and all the columns so that would be 3 x 758 as the source. You cannot store 2304 elements in a space only big enough for 1536.
  댓글 수: 5
Walter Roberson
Walter Roberson 2018년 11월 23일
Within the context of the code, what good does mIm do you? What good does bhIm do you? Why do they exist? How big are they expected to be? How do they fit into the computation? We know that hIm exists because it is the output variable. Why does hIm end up with places that need to be copied onto? What should be the source for that copying?
Chidiebere Ike
Chidiebere Ike 2018년 11월 23일
편집: Chidiebere Ike 2018년 11월 23일
Based on my little knowlege, mlm has no relevance as its only to estimate array size and can be %% commented. bhIm is considered bicubic results of the input low resolution image lIm. The previous code (function file named "L1SR") and the below code (function file named "scaleup_Yang") both of which are called in the main code. The Subscripted assignment dimension mismatch error was generated when I uncomment scaleup_Yang file in main code while trying to compare it with other methods called up in the main file. The error can be traced on this scaleup_Yang function file below where LISR was used on the last line of the code. That how the previous code (LISR) fits into the computations of scaleup_Yang results to reconstruct final results.
Please how do i solve this issue?
function ReconIm = scaleup_Yang(lowIm, upscaling)
% Image super-resolution using sparse representation
d = 'CVPR08-SR';
addpath(d, [d '/Solver'], [d '/Sparse_coding'], [d '/Sparse_coding/sc2']);
tr_dir = 'CVPR08-SR/Data/Training'; % path for training images
% =====================================================================
% specify the parameter settings
patch_size = 3; % patch size for the low resolution input image
overlap = 2; % overlap between adjacent patches
lambda = 0.1; % sparsity parameter
zooming = 3; % zooming factor, if you change this, the dictionary needs to be retrained.
if exist('upscaling','var')
zooming = upscaling; % zooming factor, if you change this, the dictionary needs to be retrained.
end
regres = 'L1'; % 'L1' or 'L2', use the sparse representation directly, or use the supports for L2 regression
% =====================================================================
% training coupled dictionaries for super-resolution
if zooming==3
load([d '/Data/Dictionary/Dictionary.mat']);
else
if ~exist([d '/Data/Dictionary/Dictionary' num2str(zooming) '.mat'],'file')
num_patch = 50000; % number of patches to sample as the dictionary
codebook_size = 1024; % size of the dictionary
regres = 'L1'; % 'L1' or 'L2', use the sparse representation directly, or use the supports for L2 regression
% =====================================================================
% training coupled dictionaries for super-resolution
if ~exist([d '/Data/Dictionary/smp_patches' num2str(zooming) '.mat'],'file')
disp('Sampling image patches...');
[Xh, Xl] = rnd_smp_dictionary(tr_dir, patch_size, zooming, num_patch);
save([d '/Data/Dictionary/smp_patches' num2str(zooming) '.mat'], 'Xh', 'Xl');
else
load ([d '/Data/Dictionary/smp_patches' num2str(zooming) '.mat']);
end
[Dh, Dl] = coupled_dic_train(Xh, Xl, codebook_size, lambda);
save([d '/Data/Dictionary/Dictionary' num2str(zooming) '.mat'], 'Dh', 'Dl');
else
load([d '/Data/Dictionary/Dictionary' num2str(zooming) '.mat']);
end
end
% ======================================================================
% Super-resolution using sparse representation
disp('Start superresolution...');
ReconIm = L1SR(lowIm, zooming, patch_size, overlap, Dh, Dl, lambda, regres);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 11월 22일
편집: madhan ravi 2018년 11월 22일
  댓글 수: 14
Walter Roberson
Walter Roberson 2018년 11월 24일
bhIm = imresize(lIm, zooming, 'bicubic');
whereas in this present code, you replaced zooming with 3. If it is left as zooming then there is no conflict with the rest of the code.
Chidiebere Ike
Chidiebere Ike 2018년 11월 24일
편집: Chidiebere Ike 2018년 11월 24일
You are right. I observed that ealier brforebefore now and resolved it already. Thanks for your seupport, You are th best!

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by