Issue with imresize, resizeParseInputs

7 次查看(过去 30 天)
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 个评论
Bryce
Bryce 2024-1-2
%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

请先登录,再进行评论。

采纳的回答

DGM
DGM 2024-1-2
编辑:DGM 2024-1-2
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 个评论
Bryce
Bryce 2024-1-2
编辑:Bryce 2024-1-2
Thanks I got a result with this. I just need to edit the image for the results I wanted results

请先登录,再进行评论。

更多回答(1 个)

Cris LaPierre
Cris LaPierre 2024-1-2
编辑:Cris LaPierre 2024-1-2
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{:});

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by