nourani / LBP

C++ implementation of the Local Binary Pattern texture descriptors. This class integrates with OpenCV and FFTW3 to bring a complete and fast implementation of the popular descriptors: LBP u2, ri, riu2 & hf. The routines for calculating these descriptors are inspired by the Matlab code of the original authors.
GNU General Public License v3.0
97 stars 60 forks source link

hf-lbp on mask image #11

Closed deter3 closed 7 years ago

deter3 commented 7 years ago

using python2.7 and opencv 2.4.13 .

image_path ="~/237720229_2.jpg" image1 = cv2.imread(image_path,cv2.IMREAD_GRAYSCALE) labelMask = np.zeros(image1.shape[:2], dtype="uint8") labelMask[0:20,0:20] = 255 l = lbp.LBP(10, lbp.LBP_MAPPING_HF) l.calcLBP(image1) hist = l.calcHist(labelMask).getHist() print hist.shape

I got an error

`OpenCV Error: Assertion failed (mask.size() == imsize && mask.channels() == 1) in histPrepareImages, file /Users/deter3/downloads/opencv-2.4.13/modules/imgproc/src/histogram.cpp, line 161 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/deter3/downloads/opencv-2.4.13/modules/imgproc/src/histogram.cpp:161: error: (-215) mask.size() == imsize && mask.channels() == 1 in function histPrepareImages

Abort trap: 6`

I checked both image and mask shape are the same , both dtype are unit8 .

If i use hist = l.calcHist().getHist() , no problem . But it is histogram for the whole image .

nourani commented 7 years ago

Hi, The issue is that when you calculate LBP on an image its size will reduce depending on the size of the radius parameter!

In you example, you are calculating with the default value of r=1 and as such your image is 2 pixels smaller in width and height.

You can either take care of this yourself and make the mask smaller or use the built-in parameter borderCopy=True: l.calcLBP(image1, 1, True)

Hope this helps

deter3 commented 7 years ago

yes , it worked now and thanks a lot ! I noticed you also update the python test sample , which is easier to understand how to implement it .

nourani commented 7 years ago

Hi Glad it worked out. I found the old test case insufficient myself so changed it :)

deter3 commented 7 years ago

Hi ,

Is there any plan to implement GPU for masked image ? I just compiled on GPU ubuntu , and found GPU can not calculate masked image . It requires 30-40 seconds to calculate 500 masked patches for one image on CPU , which is the bottleneck for my project . So I tried GPU and wish to speed up LBP calculation .

thanks

nourani commented 7 years ago

The GPU implementation was just a test. It is not complete or optimal!

I am not a GPU expert so I'm not going to expand that part. But do feel free to contribute if you can.

deter3 commented 7 years ago

I am having 400-500 patches per image . Applying hf-lbp on masked images is really time and cpu consuming job , which takes around 40-60s to accomplish the features extraction . I will have to learn some CUDA programming to see the possibilities of applying hf-lbp on masked images . I will update to you if I have some clue of how to do it .

nourani commented 7 years ago

Well this sounds like a great task to apply GPU processing. Good luck and love to hear how you go about it