lucasb-eyer / pydensecrf

Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.
MIT License
1.96k stars 417 forks source link

Hi, do the Non-RGB cases mentioned in the manual cover more than 3-channel cases? #81

Open aalennku opened 5 years ago

aalennku commented 5 years ago

Hi, thanks for such a detailed beginner's guide and manual.

I am confused on the Non-RGB cases, as the instance is presented on Greyscale images. Recently, I m using this wonderful package on an image has more than 3-channels. However, the CPP codes seem to indicate they are designed for RGB images, before the Python wrapping. For example, the codes in

pydensecrf/densecrf/src/densecrf.cpp

void DenseCRF2D::addPairwiseBilateral ( float sx, float sy, float sr, float sg, float sb, const unsigned char* im, LabelCompatibility * function, KernelType kernel_type, NormalizationType normalization_type ) {
    MatrixXf feature( 5, N_ );
    for( int j=0; j<H_; j++ )
        for( int i=0; i<W_; i++ ){
            feature(0,j*W_+i) = i / sx;
            feature(1,j*W_+i) = j / sy;
            feature(2,j*W_+i) = im[(i+j*W_)*3+0] / sr;
            feature(3,j*W_+i) = im[(i+j*W_)*3+1] / sg;
            feature(4,j*W_+i) = im[(i+j*W_)*3+2] / sb;
        }
    addPairwiseEnergy( feature, function, kernel_type, normalization_type );
}

It will be great if anyone could help me with where does the Python part take care of a more than 3 channeled case.

Thank you all for your attention.

92xianshen commented 4 years ago

Hi, I have no idea if it is helpful but you can have a look at my repo of a python-implemented Dense CRF.

https://github.com/92xianshen/PyDCRF

You can revise the _compute_bilateral_kernel in high_dim_filter.py to fit the Non-RGB case.