Issue with imresize, resizeParseInputs

15 views (last 30 days)
Bryce
Bryce on 2 Jan 2024
Edited: Bryce on 2 Jan 2024
https://www.mathworks.com/matlabcentral/answers/2065691-brace-indexing-into-the-result-of-a-function-call-is-not-supported
Error using resizeParseInputs
Expected input number 2, [MROWS NCOLS], to be positive.
Error in matlab.images.internal.resize.resizeParseInputs>scaleOrSize (line 215)
validateattributes(arg, {'numeric'}, {'vector', 'real', 'positive'}, ...
Error in matlab.images.internal.resize.resizeParseInputs>parsePreMethodArgs (line 163)
[scale, output_size] = scaleOrSize(next, next_arg);
Error in matlab.images.internal.resize.resizeParseInputs (line 28)
parsePreMethodArgs(varargin, method_arg_idx, first_param_string_idx);
Error in imresize (line 153)
params = matlab.images.internal.resize.resizeParseInputs(args{:});
Error in focusStack>recontructFromPyramid (line 59)
expanded = imresize(resultImage, size(pyramid{level}), 'bilinear');
Error in focusStack (line 21)
resultImage = recontructFromPyramid(blendedPyramid);
Hello, I had another issue with the code from the link. I understand that the issue may stem form the argument for the for loop being negative when the input for resize needs to be positive. Is there a way to make this work?
  2 Comments
Bryce
Bryce on 2 Jan 2024
%focus stacking function using Laplacian pyramid
function resultImage = focusStack(imageStack)
numImages = numel(imageStack);
%Convert images to double for processing
for i = 1:numImages
imageStack{i} = im2double(imageStack{i});
end
%Initialize Laplacian pyrimid for each image
laplacianPyramids = cell(1, numImages);
for i = 1:numImages
laplacianPyramids{i} = laplacianPyramid(imageStack{i});
end
%combine Laplacian pyramid to create the final result
blendedPyramid = blendLaplacianPyramids(laplacianPyramids);
%Reconstruct the final focus-stacked Image
resultImage = recontructFromPyramid(blendedPyramid);
end
% Laplacian pyramid generation for an image
function pyramid = laplacianPyramid(image)
levels = 12; %Number of pyramid levels (adjust as needed)
pyramid = cell(1, levels);
pyramid{1} = image;
for i = 2:levels
smoothed = imgaussfilt(pyramid{i-1}, 2); %Apply Gausian smoothing
difference = pyramid{i-1} -smoothed; %Compute difference
pyramid{i} = difference;
end
end
%blend the laplacian pyramid to create the final result
function blendedPyramid = blendLaplacianPyramids(pyramid)
numLevels = numel(pyramid{1});
blendedPyramid = cell(1, numLevels);
for level = 1:numLevels
blendedLevel = zeros(size(pyramid{1}{level}));
for level = 1:numel(pyramid)
blendedLevel = blendedLevel + pyramid{1}{level};
end
blendedPyramid{level} = blendedLevel;
end
end
%Reconstruct image from blended Laplacian
function resultImage = recontructFromPyramid(pyramid)
numLevels = numel(pyramid);
resultImage = pyramid{numLevels};
for level = numLevels-1:-1:1
expanded = imresize(resultImage, size(pyramid{level}), 'bilinear');
resultImage = expanded + pyramid{level};
end
end
Here is the code

Sign in to comment.

Accepted Answer

DGM
DGM on 2 Jan 2024
Edited: DGM on 2 Jan 2024
See the comments. It ran without errors, but I don't know if the output is right or if I'm using it correctly.
%blend the laplacian pyramid to create the final result
function blendedPyramid = blendLaplacianPyramids(pyramid)
numLevels = numel(pyramid{1});
blendedPyramid = cell(1, numLevels);
for level = 1:numLevels % this loop variable is already called 'level'
blendedLevel = zeros(size(pyramid{1}{level}));
for plevel = 1:numel(pyramid) % so name this something different
blendedLevel = blendedLevel + pyramid{1}{plevel};
end
blendedPyramid{level} = blendedLevel;
end
end
%Reconstruct image from blended Laplacian
function resultImage = recontructFromPyramid(pyramid)
numLevels = numel(pyramid);
resultImage = pyramid{numLevels};
for level = numLevels-1:-1:1
% geometry passed to imresize() can't be longer than 2
expanded = imresize(resultImage, size(pyramid{level},1:2), 'bilinear');
resultImage = expanded + pyramid{level};
end
end
  1 Comment
Bryce
Bryce on 2 Jan 2024
Edited: Bryce on 2 Jan 2024
Thanks I got a result with this. I just need to edit the image for the results I wanted results

Sign in to comment.

More Answers (1)

Cris LaPierre
Cris LaPierre on 2 Jan 2024
Edited: Cris LaPierre on 2 Jan 2024
At least one of your resize dimensions is 0. It appears, then, that your code is producing a result you did not anticipate. Check your code and if necesesary add a check so that your resize dimensions can never be 0.
img = imread("peppers.png");
% This works
img1 = imresize(img,[5,5],"bilinear");
% This reproduces your error
img2 = imresize(img,[0,5],"bilinear");
Error using resizeParseInputs
Expected input number 2, [MROWS NCOLS], to be positive.

Error in matlab.images.internal.resize.resizeParseInputs>scaleOrSize (line 215)
validateattributes(arg, {'numeric'}, {'vector', 'real', 'positive'}, ...

Error in matlab.images.internal.resize.resizeParseInputs>parsePreMethodArgs (line 163)
[scale, output_size] = scaleOrSize(next, next_arg);

Error in matlab.images.internal.resize.resizeParseInputs (line 28)
parsePreMethodArgs(varargin, method_arg_idx, first_param_string_idx);

Error in imresize (line 153)
params = matlab.images.internal.resize.resizeParseInputs(args{:});

Community Treasure Hunt

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

Start Hunting!