Ask Your Question
3

Is it poosible to make OpenCV read multiple page tiff

asked 2016-03-16 11:15:42 -0600

essamzaky gravatar image

OpenCV reads only the first page

Is it poosible to make OpenCV read multiple page tiff ?

if OpenCV can not read , what is the exteranl libray can extract the tiff pages and how to pass the data again to OpenCV

any help is appriciated

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
5

answered 2016-03-17 06:03:05 -0600

kbarni gravatar image

The best way to read TIFF files is using the libtiff library.

It supports every feature of the TIFF file format (multi-page, multi-channel, etc.) Other libraries implement only a part of the standard (generally grayscale or rgb 8-bit images). Libtiff is also cross-platform.

I already wrote an answer about using libtiff in OpenCV for multispectral images. Check the library documentation how to modify the code for multipage images.

edit flag offensive delete link more

Comments

Thankx @kbrani , it seems libtiff is the best option but it needs a lot of work to do , if you have already wtitten function to read multiple tiff it will be appriciated , currently i found library called liptonica, it's already using tibtiff too , alot of posts says it's very stable and good handling for tiff files , it will minimize the process of handling tiff from scratch , i'm trying to build the 1.73 leptonica library on VS2010 not succeded till now..

essamzaky gravatar imageessamzaky ( 2016-03-17 09:36:27 -0600 )edit
3

answered 2016-03-18 08:20:27 -0600

mshabunin gravatar image

Try cv::imreadmulti from OpenCV 3.1: documentation

edit flag offensive delete link more

Comments

good to know that OpenCV going to handle multiple tiff , but I still did understand imreadmulti documentation , if I have an image with unknown number of pages , who will direct me to use imread or imreadmulti , another issue imreadmulti read all pages in memory (verctor of MAT) , I have some books may reach to 1000 pages , loading all pages will consume most of device memory , I think it's better to be implemented as follow

1-Function to get number of pages .
2-If number of pages is one we can call imread 
3-If Number of pages larger than 1 we can call imreadmulti
4-Do not load all pages in memory , just open the required index.
5-If the user need all pages , he will use the pages counter obtained from point 1 and loop all pages.
essamzaky gravatar imageessamzaky ( 2016-03-18 14:06:38 -0600 )edit

@essamzaky you can open an issue here as new feature request. if you can change and compile OpenCV source. it is not too hard to implement your imreadmulti function. take a look the source

sturkmen gravatar imagesturkmen ( 2016-05-22 16:00:03 -0600 )edit

thanks @sturkmen , i had open an issue imreadmulti issue currently i'm very busy , when i have time i will try to implement multiple page according what i saw in other commertioal libraries

essamzaky gravatar imageessamzaky ( 2016-05-23 04:36:26 -0600 )edit
1

answered 2016-03-16 13:33:14 -0600

Guyygarty gravatar image

Re external libraries, that would depend on your OS and compiler. Using Microsoft Visual C++ you can use a TiffBitmapDecoder object. The code below may be overly complicated but it should work.

Stream^ imageStreamSource = gcnew FileStream(FileName, FileMode::Open, FileAccess::Read, FileShare::Read);
TiffBitmapDecoder^ decoder = gcnew TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
BitmapSource^ bitmapSource = decoder->Frames[FrameNumber];
int width=bitmapSource->PixelWidth;
int height=bitmapSource->PixelHeight;
int bitsPerPixel=bitmapSource->Format.BitsPerPixel; 
Type=;//you'll need to figure this one out
int stride = (width * bitsPerPixel + 7) / 8;//this may need to change for color images
array<System::Byte>^ pixels = gcnew array<System::Byte>(height * stride);
bitmapSource->CopyPixels(pixels,stride,0);
Mat Img=Mat(Height,Width,Type,&pixels[0],Stride);

guy

edit flag offensive delete link more

Comments

Thanks @Guyygarty , it seems that TiffBitmapDecoder is part of .Net Framework , actually I'm using native c++ dll for windows, I do not use .Net framework , I'm developing the dll using MS visual studio , so is there any other library works for windows c++ .

essamzaky gravatar imageessamzaky ( 2016-03-16 16:36:04 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-03-16 11:15:42 -0600

Seen: 11,551 times

Last updated: Mar 18 '16