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

4 visualizaciones (últimos 30 días)
Chidiebere Ike el 22 de Nov. de 2018
Editada: Chidiebere Ike el 24 de Nov. de 2018
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
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Walter Roberson el 22 de Nov. de 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 comentariosMostrar 3 comentarios más antiguosOcultar 3 comentarios más antiguos
Walter Roberson el 23 de Nov. de 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 el 23 de Nov. de 2018
Editada: Chidiebere Ike el 23 de Nov. de 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
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
end
[Dh, Dl] = coupled_dic_train(Xh, Xl, codebook_size, lambda);
save([d '/Data/Dictionary/Dictionary' num2str(zooming) '.mat'], 'Dh', 'Dl');
else
end
end
% ======================================================================
% Super-resolution using sparse representation
disp('Start superresolution...');
ReconIm = L1SR(lowIm, zooming, patch_size, overlap, Dh, Dl, lambda, regres);

Iniciar sesión para comentar.

### Más respuestas (1)

madhan ravi el 22 de Nov. de 2018
size(hIm(1:3, :)) and size( bhIm(1:3, :)) have to be the same to get rid of your error.
##### 14 comentariosMostrar 12 comentarios más antiguosOcultar 12 comentarios más antiguos
Walter Roberson el 24 de Nov. de 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 el 24 de Nov. de 2018
Editada: Chidiebere Ike el 24 de Nov. de 2018
You are right. I observed that ealier brforebefore now and resolved it already. Thanks for your seupport, You are th best!

Iniciar sesión para comentar.

### Categorías

Más información sobre ROI-Based Processing en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by