Dear sir, I see in scikitimage have LBP in package feature in texture.pyx and texture.py . With LBP is the center pixel's value is greater than the neighbor's value, write "0". Otherwise, write "1". With code as : # signed / thresholded texture for i in range(P): if texture[i] - image[r, c] >= 0: signed_texture[i] = 1 else: signed_texture[i] = 0 Local ternary patterns (LTP) are an extension of Local binary patterns (LBP), Unlike LBP, it does not threshold the pixels into 0 and 1, rather it uses a threshold constant to threshold pixels into three values. Considering k as the threshold constant, c as the value of the center pixel, a neighboring pixel p, the result of threshold is: 1 if p >c+k 0 if p > c-k && p <c+k 1 if p < c-k with my code as : # signed / thresholded texture for i in range(P): if texture[i] - (image[r, c]+T) > 0: signed_texture[i] = 1 elif texture[i] - (image[r, c]-T) < 0: signed_texture[i] = -1 elif texture[i] - (image[r, c]+T) <= 0 && texture[i] - (image[r, c]-T) >= 0: signed_texture[i] = 0 but i not sure this is correct with python , Pls help me In C++ i see code : unsigned short lut[8][3]; int radius; float thresholdPos; float thresholdNeg; FeatureLTP() : radius(1) , thresholdPos( 0.1f) , thresholdNeg(-0.1f) { unsigned short cnt = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 3; j++) lut[i][j] = cnt++; cnt++; //we skip the 4th number (only three patterns) } } int operator() (const Mat &I, Mat &fI) const { CV_Assert(I.isContinuous() && (I.channels() == 1)); Mat_<float> m(I); Mat_<ushort> n(m.size()); n = 0; const float *p = (const float*)m.ptr(); for (int r=radius; r<m.rows-radius; r++) { for (int c=radius; c<m.cols-radius; c++) { const float cval = p[r * m.cols + c]; static const int off[8][2] = {-1,-1, -1,0, -1,1, 0,1, 1,1, 1,0, 1,-1, 0,-1}; for (int li=0; li<8; li++) { // walk neighbours: int y = r + off[li][0] * radius; int x = c + off[li][1] * radius; float diff = p[y * m.cols + x] - cval; n(r,c) += (diff > thresholdPos) ? lut[li][0] : (diff < thresholdNeg) ? lut[li][1] : lut[li][2]; } } } fI = n; return 256; } this is difference with python ? Pls help me , I new python and c++ thankyou so much
Hello Jack, I think you may have found the wrong mailing list, this one is for the yt simulation analysis toolkit. If you need help with scikit-image, their mailing list is here: https://mail.python.org/mailman3/lists/scikit-image.python.org/ Good luck, Ben On Thu, Sep 23, 2021 at 3:30 PM <jackyhuynh30@gmail.com> wrote:
Dear sir, I see in scikitimage have LBP in package feature in texture.pyx and texture.py . With LBP is the center pixel's value is greater than the neighbor's value, write "0". Otherwise, write "1". With code as : # signed / thresholded texture for i in range(P): if texture[i] - image[r, c] >= 0: signed_texture[i] = 1 else: signed_texture[i] = 0 Local ternary patterns (LTP) are an extension of Local binary patterns (LBP), Unlike LBP, it does not threshold the pixels into 0 and 1, rather it uses a threshold constant to threshold pixels into three values. Considering k as the threshold constant, c as the value of the center pixel, a neighboring pixel p, the result of threshold is: 1 if p >c+k 0 if p > c-k && p <c+k 1 if p < c-k with my code as : # signed / thresholded texture for i in range(P): if texture[i] - (image[r, c]+T) > 0: signed_texture[i] = 1 elif texture[i] - (image[r, c]-T) < 0: signed_texture[i] = -1 elif texture[i] - (image[r, c]+T) <= 0 && texture[i] - (image[r, c]-T) >= 0: signed_texture[i] = 0 but i not sure this is correct with python , Pls help me In C++ i see code : unsigned short lut[8][3]; int radius; float thresholdPos; float thresholdNeg;
FeatureLTP() : radius(1) , thresholdPos( 0.1f) , thresholdNeg(-0.1f)
{ unsigned short cnt = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 3; j++) lut[i][j] = cnt++; cnt++; //we skip the 4th number (only three patterns) } }
int operator() (const Mat &I, Mat &fI) const { CV_Assert(I.isContinuous() && (I.channels() == 1));
Mat_<float> m(I); Mat_<ushort> n(m.size()); n = 0;
const float *p = (const float*)m.ptr(); for (int r=radius; r<m.rows-radius; r++) { for (int c=radius; c<m.cols-radius; c++) { const float cval = p[r * m.cols + c]; static const int off[8][2] = {-1,-1, -1,0, -1,1, 0,1, 1,1, 1,0, 1,-1, 0,-1}; for (int li=0; li<8; li++) { // walk neighbours: int y = r + off[li][0] * radius; int x = c + off[li][1] * radius; float diff = p[y * m.cols + x] - cval; n(r,c) += (diff > thresholdPos) ? lut[li][0] : (diff < thresholdNeg) ? lut[li][1] : lut[li][2]; } } } fI = n; return 256; } this is difference with python ? Pls help me , I new python and c++ thankyou so much _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: kellerbw@mcmaster.ca
participants (2)
-
Ben Keller
-
jackyhuynh30@gmail.com