imread doesn't open pbm/tiff images

asked 2015-07-31 09:00:11 -0500

oxeed gravatar image

Hi, I have a code that works with low dynamic range images (like png, jpeg and other normal extensions), but it can't read pbm/tiff files. What can I do?

cv::Mat img = cv::imread(argv[1], CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);

if (img.rows*img.cols==0){
    printf("\nImage not acquired.");
    return 0;

..of course, if I load one of those kind of images, it returns 0. I've already asked on stackoverflow but nobody answerd me. I'm getting crazy.

edit retag flag offensive close merge delete



Could you post one of those images you can't load?

LorenaGdL gravatar imageLorenaGdL ( 2015-07-31 09:21:21 -0500 )edit

Thank you for answering :) Actually, any image with a pbm/tiff extension won't be loaded. I even made a 32byte per channel 2x2 pixel image and it didn't get it. If you still need some image I'll upload them :) Thanks again!

oxeed gravatar imageoxeed ( 2015-07-31 10:32:21 -0500 )edit

It's better to check with one of your images, because I can open .tiff images without problems. Also, please say which version of OpenCV you're working with

LorenaGdL gravatar imageLorenaGdL ( 2015-07-31 10:35:41 -0500 )edit

I'm pretty sure it's 2.4.11

This is the 2x2 pixel image I was talking about (.tiff)

And this is a part of a bigger .tiff image:

The same images converted with photoshop in pbm can't be opened neither.

(I can't upload them directly because I'm a new user and I can't answer to my own posts. All I can do is give you links :) )

oxeed gravatar imageoxeed ( 2015-07-31 11:11:58 -0500 )edit

It's ok to me if you give links but... uploading the images have automatically convert them into .png images. Can't you upload them anywhere else preserving the format?

LorenaGdL gravatar imageLorenaGdL ( 2015-07-31 11:17:18 -0500 )edit

This link should automatically download an example tif image, which I tested and can't open

oxeed gravatar imageoxeed ( 2015-07-31 11:22:35 -0500 )edit

Don't know if it can help, but I tried to download a pbm image to give you. I took this one ( and, instead of not opening the file, the program crashed. The difference between the pbm files I make with photoshop and this one is that the downloaded one is b/n.

oxeed gravatar imageoxeed ( 2015-07-31 11:27:47 -0500 )edit

I don't have problems reading the .pbm file, even using flags. I can open the .tif image without the flags, but it does cause an error with the flags, don't know why. I don't really trust the .tif sample I downloaded. I'm using OpenCV 2.4.10

LorenaGdL gravatar imageLorenaGdL ( 2015-07-31 12:03:00 -0500 )edit

So you don't have any guess.. right?

Should it help somehow, this is the include&define section:

    #include <cstdio>
#include <cmath>

#include <windows.h>

#include <opencv/cv.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/photo/photo.hpp>

oxeed gravatar imageoxeed ( 2015-07-31 12:19:22 -0500 )edit

wow, there are too many things in there. Things I'd definitely delete:

#include <opencv/cv.h>
#include <opencv2/highgui/highgui_c.h>


And I guess you know what you're doing with that windows define and include

LorenaGdL gravatar imageLorenaGdL ( 2015-07-31 12:24:57 -0500 )edit