2

I notice that this simple ArrayFire program is causing loaded TIFF images to be heavily distorted:

#include <iostream>
#include <arrayfire.h>

int main( int argc, char** argv ) {
    af::array img = af::loadImage( argv[1] );

    double mn, mx; 
    unsigned idxn, idxx;
    af::min( &mn, &idxn, img );
    af::max( &mx, &idxx, img );

    std::cout << "Image size = " << img.dims()[0] << ", " << img.dims()[1] << '\n';
    std::cout << "Data type = " << img.type() << '\n';
    std::cout << "Min = " << mn << " (at " << idxn << ")\n";
    std::cout << "Max = " << mx << " (at " << idxx << ")\n";

    af::saveImage( argv[2], img );

    return 0;
}

I then compile and run on a simple (monochrome) image:

./a.out orig.tif out.tif

with the following output:

Image size = 256, 256
Data type = 0
Min = 0 (at 65535)
Max = 81.5025 (at 31356)

When I visualize these images I get the following result: ArrayFire TIFF image distortion

which of course is not what ArrayFire is expected to do; I would expect it to dump the exact same image out since I didn't make any changes to it. Unfortunately I don't know enough about the TIFF image format or the graphics backend of ArrayFire to understand what is going on. Am I doing something wrong while loading the image? (I followed the ArrayFire documentation for loadImage and saveImage).

I also tried using loadImageNative and saveImageNative alternatively, but the latter returns a 4-layer TIFF image while the original image is only a 1-layer TIFF.

Any help at all from ArrayFire experts would be great.

Thanks!

sid
  • 131
  • 3
  • 1
    TIFF is only a container for image and it can contains many different image encodings. Some formats may be difficult to present (for ex. 36bit image on 24bit color screen), Also displayed result may be different on different image viewers. And adding to this problems encoding image again may result in strange behavior. It is really difficult to say where is the problem without knowing what kind of image you want to use. – Logman Apr 03 '17 at 17:30
  • @Logman Thanks for your reply. For the record, the image above was generated in Matplotlib, and the result when I plot using Matlab is pretty much identical. – sid Apr 03 '17 at 18:27
  • Figured this out: I realized orig.tif was created with the Python module tifffile, which dumps to unsigned 64-bit integer TIFFs by default, which ArrayFire seems to have some trouble understanding. When I save the same image cast as numpy.uint32, ArrayFire is able to read it correctly, even though it still writes 8-bit TIFFs; turns out it scales the original pixel values down to a maximum of 255. – sid Apr 05 '17 at 05:05
  • Write this as a answer as it could help to resolve problems to further readers. – Logman Apr 05 '17 at 15:49
  • Can you print the dimensions of the array loaded using loadImageNative function and share that output here as well? – pradeep Apr 05 '17 at 16:33

0 Answers0