Метод OcTree в Matlab - PullRequest
       77

Метод OcTree в Matlab

0 голосов
/ 13 июля 2020

Я работаю над проектом квантования цвета в Matlab. Я хочу добавить метод OcTree. Я пробовал использовать этот код, который нашел в Википедии: https://en.wikipedia.org/wiki/Octree, но он не работает, и я не знаю почему.

    % Read the original RGB image
    Img = imread('image.jpg');
    % Extract pixels as RGB point triplets
    pts = reshape(Img,[],3);
    % Create OcTree decomposition object using a target bin capacity
    OT = OcTree(pts,'BinCapacity',ceil((size(pts,1) / 256) *7)); 
    % Find which bins are "leaf nodes" on the octree object
    leafs = find(~ismember(1:OT.BinCount, OT.BinParents) & ...
        ismember(1:OT.BinCount,OT.PointBins));
    % Find the central RGB location of each leaf bin
    binCents = mean(reshape(OT.BinBoundaries(leafs,:),[],3,2),3);
     
    % Make a new "indexed" image with a color map
    ImgIdx = zeros(size(Img,1), size(Img,2));
    for i = 1:length(leafs)
        pxNos = find(OT.PointBins==leafs(i));
        ImgIdx(pxNos) = i;
    end
    ImgMap = binCents / 255; % Convert 8-bit color to MATLAB rgb values
     
    % Display the original 532818-color image and resulting 184-color image 
    figure
    subplot(1,2,1), imshow(Img)
    title(sprintf('Original %d color image', size(unique(pts,'rows'),1)))
    subplot(1,2,2), imshow(ImgIdx, ImgMap)
    title(sprintf('Octree-quantized %d color image', size(ImgMap,1)))

Это метод OcTree, который у меня есть:

function [binDepths,binParents,binCorners,pointBins] = OcTree(points)
 
binDepths = [0]     % Initialize an array of bin depths with this single base-level bin
binParents = [0]    % This base level bin is not a child of other bins
binCorners = [min(points) max(points)] % It surrounds all points in XYZ space
pointBins(:) = 1    % Initially, all points are assigned to this first bin
divide(1)           % Begin dividing this first bin
 
function divide(binNo)
    
% If this bin meets any exit conditions, do not divide it any further.
binPointCount = nnz(pointBins==binNo)
binEdgeLengths = binCorners(binNo,1:3) - binCorners(binNo,4:6)
binDepth = binDepths(binNo)
exitConditionsMet = binPointCount<value || min(binEdgeLengths)<value || binDepth>value
if exitConditionsMet
    return; % Exit recursive function
end
 
% Otherwise, split this bin into 8 new sub-bins with a new division point
newDiv = (binCorners(binNo,1:3) + binCorners(binNo,4:6)) / 2
for i = 1:8
    newBinNo = length(binDepths) + 1
    binDepths(newBinNo) = binDepths(binNo) + 1
    binParents(newBinNo) = binNo
    binCorners(newBinNo) = [one of the 8 pairs of the newDiv with minCorner or maxCorner]
    oldBinMask = pointBins==binNo
    % Calculate which points in pointBins==binNo now belong in newBinNo 
    pointBins(newBinMask) = newBinNo
    % Recursively divide this newly created bin
    divide(newBinNo)
end

Когда я запускаю его, возникает следующая ошибка: Ошибка при использовании OcTree Слишком много входных аргументов

Я также пробовал другие примеры, которые я нашел на веб-странице Matlab, но получил ту же ошибку. Я изменил параметры, но он не работает должным образом.

Мне нужна помощь, пожалуйста! Заранее большое спасибо :)

...