Brace indexing into the result of a function call is not supported

31 ビュー (過去 30 日間)
Bryce
Bryce 2024 年 1 月 2 日
コメント済み: DGM 2024 年 1 月 2 日
Hello I was attempting to run a code I had. The code is below:
%focus stacking function using Laplacian pyramid
function resultImage = focusStack(imageStack)
numImages = numel(imageStack);
%Convert images ti double for processing
for i = 1:numImages
imageStack{i} = im2double(imageStack{i});
end
%Initialize Laplacian pyrimid for each image
laplacianPyramid = cell(1 , numImages);
for i = 1:numImages
laplacianPyramid{i} = laplacianPyramid(imageStack{i});
end
%combine Laplacian pyramid to create the final result
blendedPyramid = blendLaplacianPyramids(laplacianPyramid);
%Reconstruct the final focus-stacked Image
resultImage = reconstructFromPyramid(blendPyramid);
end
% Laplacian pyramid generation for an image
function pyramid = laplacianPyramid(image)
levels = 6; %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(pyramids)
numLevels = numel(pyramid{1});
blendedPyramid = cell(1, numLevels);
for level = 1:numLevels
blendedLevel = zeros(size(pyramids{1}{level}));
for level = 1:numel(pyramids)
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 = numLevel-1:-1:1
expanded = imresize(resultImage, size(pyramid{level}), 'bilinear');
resultImage = expanded + pyramid{level};
end
end
I ran the code above and got the following error:
Error: File: focusStack.m Line:
40 Column: 23
Brace indexing into the result
of a function call is not
supported. Assign the result of
'pyramid' to a variable first,
then brace index into it.
Do you know of a way to resolve this issue.

採用された回答

DGM
DGM 2024 年 1 月 2 日
編集済み: DGM 2024 年 1 月 2 日
Hm. I'm going to guess on this one.
function blendedPyramid = blendLaplacianPyramids(pyramids) % the variable is 'pyramids'
numLevels = numel(pyramid{1}); % but it's singular here
blendedPyramid = cell(1, numLevels);
for level = 1:numLevels
blendedLevel = zeros(size(pyramids{1}{level})); % plural here
for level = 1:numel(pyramids) % plural here
blendedLevel = blendedLevel + pyramid{1}{level}; % singular here
My guess is that 'pyramid' is supposed to be 'pyramids'. Since 'pyramid' isn't a defined variable, it's instead resolving as a function somewhere on your path and causing the admittedly confusing error.
  4 件のコメント
Bryce
Bryce 2024 年 1 月 2 日
Thanks again!
DGM
DGM 2024 年 1 月 2 日
no problem

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by