First time here? Check out the FAQ!

Ask Your Question
1

Save floating point TIFF images

asked Jul 28 '15

DoctorMob gravatar image

Hi team, I work with a team that uses MATLAB for image analysis. They trade floating point TIFF files for analysis. I am working through the simple read/write tutorials but am frustrated by the fact that I cannot write out a floating point TIFF file.

here is some code I've been using:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv )
{
    if ( argc != 4 )
    {
        printf("usage: DisplayImage.out <Image_Path>\n");
        return -1;
    }

    //read images from memory
    Mat A;
    A = imread( argv[1], CV_LOAD_IMAGE_UNCHANGED );
    Mat B;
    B = imread( argv[2], CV_LOAD_IMAGE_UNCHANGED );
    Mat C;
    C = imread( argv[3], CV_LOAD_IMAGE_UNCHANGED );

    //create floating point images for image manipulation
    Mat Aa;
    A.convertTo(Aa,5);
    Mat Bb;
    B.convertTo(Bb,5);
    Mat Cc;
    C.convertTo(Cc,5);

    if ( (!Aa.data) || (!Bb.data) || (!Cc.data) )
    {
        printf("Missing image data \n");
        return -1;
    }

    //subtract dark field from source image
    Mat D;
    D = Aa - Bb;
    Mat E;
    E = Cc/D;

    //save intermediate images
    imwrite("D.tiff",D);
    imwrite("E.tiff",E);

    //save image

    return 0;
}

This code compiles fine, and runs, yet it saves no images. If I rewrite the code to work with 16 bit images, it works fine. What's going on?

Thanks in advance!

Preview: (hide)

2 answers

Sort by » oldest newest most voted
1

answered Jul 28 '15

I am sorry but for both 2.4 and 3.0 the support of 32 bit TIFF images is not available

If you really want to save them in 32 bit, then you can store them in XML/YAML format using the FileStorage interface

Preview: (hide)
0

answered Jul 30 '15

DoctorMob gravatar image

updated Jul 30 '15

Instead, imagine running floating point processing on the image. When complete, convert back to CV_16U and save the image.

This does not appear to work either:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv )
{
    if ( argc != 4 )
    {
        printf("usage: DisplayImage.out <Image_Path>\n");
        return -1;
    }

    //read images from memory
    Mat A;
    A = imread( argv[1], CV_LOAD_IMAGE_UNCHANGED );
    Mat B;
    B = imread( argv[2], CV_LOAD_IMAGE_UNCHANGED );
    Mat C;
    C = imread( argv[3], CV_LOAD_IMAGE_UNCHANGED );

    //create floating point images for image manipulation
    Mat Aa;
    A.convertTo(Aa,5);
    Mat Bb;
    B.convertTo(Bb,5);
    Mat Cc;
    C.convertTo(Cc,5);

    if ( (!Aa.data) || (!Bb.data) || (!Cc.data) )
    {
        printf("Missing image data \n");
        return -1;
    }

    //subtract dark field from source image
    Mat D;
    D = Aa - Bb;
    Mat E;
    E = Cc/D;
    Mat Econvert;
    E.convertTo(Econvert,CV_16U);
    //save image
    imwrite("Econverted.tiff",E);

    return 0;
}

Please advise

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Jul 28 '15

Seen: 12,952 times

Last updated: Jul 30 '15