将多频段tiff图像加载到OpenCV C ++中

时间:2014-08-19 20:31:09

标签: c++ opencv

我尝试将8波段tiff图像加载到OpenCV C ++中,但是当我检查图像的尺寸时,它给出了3个1500 x 0像素的波段。图像是1500×1500像素,带有8个波段。有没有我错的地方?我的代码如下:

int main(int argc, char** argv)
{
    Mat Image, Normalized, ImageCopy;
    if (argc != 2){
        cout << "Define Image location" << endl;
    }
    else{
        Image = imread(argv[1], CV_LOAD_IMAGE_UNCHANGED|CV_LOAD_IMAGE_ANYDEPTH);
    }

    cout <<" Number of bands \t: " << Image.channels() << "\t Image size\t"<< Image.size() << endl;

    //Checking image validity
    if(!Image.data){
        cout << "Invalid image" <<endl;
        return -1;
    }

    waitKey(0);
    return 0;
}

1 个答案:

答案 0 :(得分:2)

我认为你运气不好,TiffDecoder::readHeader()就是这样:

  m_type = CV_MAKETYPE(CV_8U, photometric > 1 ? 3 : 1);

也就是说,它使用PHOTOMETRIC标签将通道数设置为1或3。 为了使您的代码有效,您需要根据SAMPLESPERPIXEL标记设置通道数,但不是。整个解码器似乎充满了图像是灰度或RGB的假设。即使是RGBA图像也会丢弃其Alpha通道。

您可以直接使用libtiff,使用grfmt_tiff.cpp中的OpenCV源作为指南。