Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
892 views
in Technique[技术] by (71.8m points)

image processing - Local Binary Pattern in MATLAB

I am trying to execute local binary pattern in MATLAB using the image processing toolbox. When i execute I can't get a LBP image and LBP histogram.

   clear all;
    close all;
    clc;
    I=imread('test.png');
    figure,imshow(I)
    %% Crop
    I2 = imcrop(I);
    figure, imshow(I2)
    w=size(I2,1);
    h=size(I2,2);
    %% LBP
    scale = 2.^[7 6 5; 0 -inf 4; 1 2 3]; 
    for i=2:w-1
        for j=2:h-1
            J0=I2(i,j);
            I3(i-1,j-1)=I2(i-1,j-1)>J0;
            I3(i-1,j)=I2(i-1,j)>J0;
            I3(i-1,j+1)=I2(i-1,j+1)>J0; 
            I3(i,j+1)=I2(i,j+1)>J0;
            I3(i+1,j+1)=I2(i+1,j+1)>J0; 
            I3(i+1,j)=I2(i+1,j)>J0; 
            I3(i+1,j-1)=I2(i+1,j-1)>J0; 
            I3(i,j-1)=I2(i,j-1)>J0;
            LBP(i,j)=I3(i-1,j-1)*2^7+I3(i-1,j)*2^6+I3(i-1,j+1)*2^5+I3(i,j+1)*2^4+I3(i+1,j+1)*2^3+I3(i+1,j)*2^2+I3(i+1,j-1)*2^1+I3(i,j-1)*2^0;

        end
    end
    figure,imshow(LBP)
    figure,imhist(LBP)

what is the issue.i am supposed to get numbers from 0 to 255.enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I3(i-1,j-1)=I2(i-1,j-1)>J0; creates a logical as output. If you don't go and cast this to something else, you're image will only be zeros and ones.

The easiest way is to initialize I3 outside the loop, i.e. have I3=I2; before you start looping. This way, all your assignments inside the loop get converted to whatever class I2 was.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...