簡體   English   中英

在Matlab中使用LBP后如何獲得0和1像素?

[英]How to get 0 and 1 pixel after using LBP in matlab?

我正在嘗試在MATLAB中執行本地二進制模式。 LBP正常工作,但是我的結果問題導致我想在LBP完全完成時得到這些零和一,並將所有0和1放入行向量

我試圖將所有0和1放入數組,但是8次會將所有0和1放入數組for循環的原因。 我使用的圖像是256x256,這意味着我應該得到256 0和1,但是現在我得到2048,如果我們將2048除以8,我們將得到256,這意味着8次會將0and1放入C數組,我希望現在更加清楚

這是我的代碼::::

C=[];   %%% this array collect all zeros and ones 
for i=2:r-1
    for j=2:c-1
        if x(i,j)>x(i-1,j-1)
            arr(1,1)=0;
        else
            arr(1,1)=1; 
        end
         if x(i,j)>x(i-1,j)
            arr(1,2)=0;
        else
            arr(1,2)=1; 
        end 
        if x(i,j)>x(i-1,j+1)
            arr(1,3)=0;
        else
            arr(1,3)=1; 
        end
        if x(i,j)>x(i,j+1)
            arr(1,4)=0;
        else
            arr(1,4)=1; 
                end
                if x(i,j)>x(i+1,j+1)
            arr(1,5)=0;
        else
            arr(1,5)=1; 
                end
                 if x(i,j)>x(i+1,j)
            arr(1,6)=0;
        else
            arr(1,6)=1; 
                end
             if x(i,j)>x(i+1,j-1)
            arr(1,7)=0;
        else
            arr(1,7)=1; 
             end
             if x(i,j)>x(i,j-1)
            arr(1,8)=0;
           else
            arr(1,8)=1; 
             end

             %Convert Binary to Dec
        newimg(i,j)=sum(arr.*2.^(numel(arr)-1:-1:0));  


    end


C=[C arr];   %%  I think my problem with this line to putting zeros and one to C array

end

C

如果要將所有像素的二進制序列存儲到C ,請將該語句放在兩個循環中,如下所示:

C=zeros(8,254*254);   %%% this array collect all zeros and ones 
for i=2:r-1
    for j=2:c-1

     % ... if conditions here...

        %Convert Binary to Dec
        newimg(i,j)=sum(arr.*2.^(numel(arr)-1:-1:0));  


       C(:,j-1+(i-2)*254) = arr(:);

    end    
end

請注意, C不是 256 x 256,而是254 x 254(請看循環范圍)。

我進行了設置,以便C按列存儲數據,每個像素一列

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM