Ask Your Question
1

Save floating point TIFF images

asked 2015-07-28 00:59:09 -0600

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!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2015-07-28 03:31:30 -0600

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

edit flag offensive delete link more
0

answered 2015-07-30 09:55:11 -0600

DoctorMob gravatar image

updated 2015-07-30 11:08:17 -0600

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-07-28 00:59:09 -0600

Seen: 12,513 times

Last updated: Jul 30 '15