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

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 22 Nov 2018
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 Commenti
Walter Roberson
Walter Roberson il 23 Nov 2018
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 il 23 Nov 2018
Modificato: Chidiebere Ike il 23 Nov 2018
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);

Accedi per commentare.

Più risposte (1)

madhan ravi
madhan ravi il 22 Nov 2018
Modificato: madhan ravi il 22 Nov 2018
  14 Commenti
Walter Roberson
Walter Roberson il 24 Nov 2018
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 il 24 Nov 2018
Modificato: Chidiebere Ike il 24 Nov 2018
You are right. I observed that ealier brforebefore now and resolved it already. Thanks for your seupport, You are th best!

Accedi per commentare.

Categorie

Scopri di più su Data Exploration in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by