|
Dear Sir,
I am now working for a school project where i have to read TIFF file which consists of 30 images/ pages / Directories.
Image is a 16-bit image
Uncompressed
photometric MinIsBlack
I want to read each image that are available in tiff and save them to an array of Iplimage format so that i can work with these imagaes using OpenCV library.
I am not a good programmer, so it was very hard with data types.
I am using Libtiff in Visual studio 2010.
Can you please help me with logic to get the image data from this multiple image and save them to IplImage format?
Thank you very much,
Greetings,
Veeranki
|
|
|
|
|
Hello Sumit Kapoor,
I am working on a semester project in which i have to read a tiff file which consists of 30 images and do some processing on the images.
I have to use OpenCV and openCV is not supporting to read all the images from the tiff.
I am using libtiff and compiling using Visual Studio 2010, i am getting an error LNK1136: invalid or corrupt file libtiff-bcc.lib
Can you please help me in this regards, any suggestions would be great.
My name is Sai, student from Austria,
Thank you,
Regards,
Sai Veeranki
|
|
|
|
|
I have an urgent need to convert Tiff file to BMP in .NET Please provide me the sample code how to convert Tiff to BMP.
|
|
|
|
|
Can you show which functions to call to convert a TIFF image to a simple monochrome image. Thanks.
|
|
|
|
|
I want to make friend with you my e-mail is: 583241212@qq.com
Like C++ more
|
|
|
|
|
Hi Sumit Kapoor,
i have tried your application and get it compile without any errors, but error comes when i see my output image like overlapping and only part of the image has been taken not the entire image all in all i can see my output image is distorted, i haven't change anything about your codes, but i just find out in my output not a perfect image that i expect it to be, some more when i check the application to troubleshoot my problem only to find out that when i put GetLastError() function after the LoadImage() , the result of the GetLastError() is integer 8 which means ERROR_NOT_ENOUGH_MEMORY , how come i experience this error, i am using visual studio 2005 and 256 color bitmap image...
hope you can help me point out the problem i've been googling this problem but never have i acrossed a solution for this...
looking forward to hear from you...
thank you,
reno
|
|
|
|
|
Hey...
1. Please make sure the size of bitmap is correct in your code. As I used:
m_Bitmap->GetBitmapBits(600*600 ,bmpBuffer);
2. Color of bitmap is matching with as specified in article. {256 color}
3. This code was tested in Visual Studio 6, so may be need to do some patch work. If it's not working, But IT SHOULD WORK.
4. As in this article, GlobalAlloc() is used. So make sure that you have called GlobalFree(). This may solve your memory issue.
Regards,
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Can we save 16 bits tiff using this source code?
Thanks
|
|
|
|
|
please can any one help me to convert bmp image to compressed ccitt g31d file
|
|
|
|
|
Hi
I am having jpeg compressed tiff files , which i want to open in Imaging ,
I want to chang its compression to CCIT .
How can i do so .
Any help will be appriciate
Thanks
Kiran chikhale
|
|
|
|
|
Do you have any sample for tiff to bmp?
thank you
ewre
|
|
|
|
|
I am a C# programmer currently working with Intel dialogic card to send fax.
but i m facing a problem that, Dialogic card can only handle ccitt group 4 tiff file and having some special tag values.
Can any one help me out in this stuff?
plz reply me on anil.pandya84@hotmail.com
anil
|
|
|
|
|
Hi Friends,
If you are facing Library Linking Error
then please make sure your setting as follow:
1. In Visual Studio(6.0) Goto Menu "Project >> Setting..."
2. There is Tab for "Link" in right side.(Select this)
3. There is Text Box "Object Library modules:"
Fill this Text Box with "Libtiff.lib" (without Quotes)
NOTE: if there is anything else like "libtiff.lib/nologo" then change this to "libtiff.lib"
OK! then it'll not give any linking error.
Regards,
Sumit Kapoor
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Is that upcoming project of converting BMP to TIFF done?
if so, can u upload the code?
|
|
|
|
|
hi Sumit Kapoor
I´m student spanish and my inglish is not very good sorry, Can you help me?
I make a proyect in Visual C++ 6.0 but when i build and execute all the proyect, Visual say me:
libtiff.lib/nologo /subsystem:windows /incremental:yes "/pdb:Debug/BmpToTif.pdb" /debug /machine:I386 "/out:Debug/BmpToTif.exe" /pdbtype:sept
".\Debug\BmpToTif.obj"
".\Debug\BmpToTifDlg.obj"
".\Debug\StdAfx.obj"
".\Debug\BmpToTif.res"
".\libtiff.lib"
"..\..\..\..\..\..\Archivos de programa\GnuWin32\lib\libtiff.lib"
"..\..\..\..\..\..\Archivos de programa\GnuWin32\lib\libtiff-bcc.lib"
LINK : fatal error LNK1104: cannot open file "libtiff.lib/nologo.obj"
Error executing link.exe.
I don´t know why give me this error because I think that I added the library well.
I did tools-options-directories and inclued files and lib for the GnuWin32-tiff downlanded for http://www.libtiff.org/.
Good bye and I hope his answer.
|
|
|
|
|
Hi Dear,
I think you are trying to run that in debug mode.. OK.. just do..as follow..
Project Setting >> Link >> Object/Library Modules:
Remove Value : libtiff.lib/nologo
NOT NEEDED THIS VALUE
It'll start giving one warning about MSVCRT about /NODEFAULT..for this.. set value as follow..
Project Setting >> Link >> Category >> Input ... Ingnore libraries = msvcrt
OK..bye..Enjoy coding..
Sumit K.
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
-- modified at 7:00 Thursday 9th February, 2006
|
|
|
|
|
Thank Sumit Kapoor but now Visual c++ 6.0 say me:
..\..\..\..\..\..\Archivos de programa\GnuWin32\lib\libtiff-bcc.lib : fatal error LNK1136: invalid or corrupt file
Error executing link.exe.
I think that the problem isn´t by the corrupt file because I installed two diferents versions of GnuWin32 lib tif.
Presently I have install tif 3.8.0 before I had tif 3.6.1-2.
Thank and I hope your answer.
Good bye
|
|
|
|
|
I am not sure dear about that, that may be due to confliction between files of libtiff.
For this you can do one thing, In my project I have given a libtiff.lib, instead of using this file you can use your file installed on your system. Just add that file to project.
You can try more.
Regards,
Sumit K.
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Sumit,
Can you convert 1280x960 bitmap to 1280x960 tif? Your default is set at 600x600. I try changing all the numbers to 1280x960 but its not working. An error occures at the name of the tif.
Thanks,
|
|
|
|
|
REMINDER FOR ALL READER : GlobalFree(bmpBuffer); is missing which may create memory leak; so please add this in end of function.
------------------------------------------------------------------------
Hi Dear,
I did as you said for bitmap size, but it's working fine. May be you are missing to replace any size.
May be you are using other format bitmap, This code is work fine for 256 color bitmap, so just keep in mind this format check also.
I am copy/pasting function, which may help you, If you still face any problem, just e-mail me at sumit_kapoor1980@hotmail.com
It's not sure I get time to help you, but I try.
Regards,
Sumit Kapoor
void CBmpToTifDlg::OnConvert()
{
HBITMAP hImage = (HBITMAP)LoadImage(NULL, "C:\\MyBit.bmp", IMAGE_BITMAP,
0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);
CBitmap* m_Bitmap = CBitmap::FromHandle(hImage);
// Sumit: memory allocation is still 1800x1800 in your code..
BYTE* bmpBuffer=(BYTE*)GlobalAlloc(GPTR, 1280*960);//allocate memory
// Size of bitmap as I draw by using x,y points...
m_Bitmap->GetBitmapBits(1280*960 ,bmpBuffer);
TIFF *image;
// Open the TIFF file
if((image = TIFFOpen("C:\\output.tif", "w")) == NULL)
{
printf("Could not open output.tif for writing\n");
}
TIFFSetField(image, TIFFTAG_IMAGEWIDTH,1280);
TIFFSetField(image, TIFFTAG_IMAGELENGTH,960);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE,8);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL,1);
uint32 rowsperstrip = TIFFDefaultStripSize(image, -1);
//<rec> gives better compression
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
// TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX3);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
// TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
// Start CCITTFAX3 setting
uint32 group3options = GROUP3OPT_FILLBITS+GROUP3OPT_2DENCODING;
TIFFSetField(image, TIFFTAG_GROUP3OPTIONS, group3options);
TIFFSetField(image, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
TIFFSetField(image, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, -1L);
// End CCITTFAX3 setting
//if we comment following line then Tiff will not view in Imaging
//but view in DC
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
TIFFSetField(image, TIFFTAG_XRESOLUTION, 100.0);
TIFFSetField(image, TIFFTAG_YRESOLUTION, 100.0);
char page_number[20];
sprintf(page_number, "Page %d", 1);
TIFFSetField(image, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
TIFFSetField(image, TIFFTAG_PAGENUMBER, 1, 1);
TIFFSetField(image, TIFFTAG_PAGENAME, page_number);
// Write the information to the file
BYTE *bits;
for (int y = 0; y < 960; y++)
{
bits= bmpBuffer + y*1280;
if (TIFFWriteScanline(image,bits, y, 0)==-1) MessageBox("Complete or error");
}
GlobalFree(bmpBuffer);
// Close the file
TIFFClose(image);
}
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
Hi Sumit,
I did what you say (my image is 1259x554), but I've got an screw image. it is complete, but it looks like
The changes I did:
HBITMAP hImage = (HBITMAP)LoadImage(NULL, "C:\\MyBit.bmp", IMAGE_BITMAP,
0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);
CBitmap* m_Bitmap = CBitmap::FromHandle(hImage);
// Sumit: memory allocation is still 1800x1800 in your code..
BYTE* bmpBuffer=(BYTE*)GlobalAlloc(GPTR, 1259*554);//allocate memory}
// Size of bitmap as I draw by using x,y points...
m_Bitmap->GetBitmapBits(1259*554 ,bmpBuffer);
TIFF *image;
// Open the TIFF file
if((image = TIFFOpen("C:\\output.tif", "w")) == NULL)
{
printf("Could not open output.tif for writing\n");
}
TIFFSetField(image, TIFFTAG_IMAGEWIDTH,1259);
TIFFSetField(image, TIFFTAG_IMAGELENGTH,554);
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE,8);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL,1);
uint32 rowsperstrip = TIFFDefaultStripSize(image, -1);
//<REC> gives better compression
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
// TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX3);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
// TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
// Start CCITTFAX3 setting
uint32 group3options = GROUP3OPT_FILLBITS+GROUP3OPT_2DENCODING;
TIFFSetField(image, TIFFTAG_GROUP3OPTIONS, group3options);
TIFFSetField(image, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
TIFFSetField(image, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, -1L);
// End CCITTFAX3 setting
//if we comment following line then Tiff will not view in Imaging
//but view in DC
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(image, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
TIFFSetField(image, TIFFTAG_XRESOLUTION, 200.0);
TIFFSetField(image, TIFFTAG_YRESOLUTION, 200.0);
char page_number[20];
sprintf(page_number, "Page %d", 1);
TIFFSetField(image, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
TIFFSetField(image, TIFFTAG_PAGENUMBER, 1, 1);
TIFFSetField(image, TIFFTAG_PAGENAME, page_number);
// Write the information to the file
BYTE *bits;
for (int y = 0; y < 554; y++)
{
bits= bmpBuffer + y*1259;
if (TIFFWriteScanline(image,bits, y, 0)==-1) MessageBox("Complete or error");
}
// Close the file
TIFFClose(image);
}
How can I know that the image is a 256 color bitmap???
I can see the image, but it is shown like "diagonal"
Thanks!
|
|
|
|
|
sorry, the image looks like diagonal skewed...
any idea?
Thanks!
|
|
|
|
|
Hi,
Right now, I could not check. Better, if you can play with TIFFSetField() and try setting different values.
These are settings, that actually set things like pixel per line etc. and if we give more or less then it change image to different shape.
Try changing settings. Good Luck!
Regards,
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|
I changed this:
My image is 1259X554 and I changed everything with this value, but the last one
for (int y = 0; y < 554; y++)
{
bits= bmpBuffer + y*1260;
if (TIFFWriteScanline(image,bits, y, 0)==-1)
It worked fine now
Now, do you know how can I get the dimensions of the image (x,y) without opening any sw? Is any way to get dimensions automatically?
Thanks!
|
|
|
|
|
Try following methods for getting..size...
For CBitmap objects we can use the GetBitmap() function to determine the height and width of the bitmap.
// The variable bitmap is a CBitmap object
BITMAP bm;
bitmap.GetBitmap( &bm );
bmWidth = bm.bmWidth;
bmHeight = bm.bmHeight;
If you have a HBITMAP, you can attach it to a CBitmap object and use the method shown above or you can use
// The variable hBmp is a HBITMAP
BITMAP bm;
::GetObject( hBmp, sizeof( bm ), &bm );
bmWidth = bm.bmWidth;
bmHeight = bm.bmHeight;
For images in a BMP file, you can use something like
CFile file;
// sBMPFileName is the BMP filename
if( !file.Open( sBMPFileName, CFile::modeRead) )
return ;
BITMAPFILEHEADER bmfHeader;
// Read file header
if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader))
return ;
// File type should be 'BM'
if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B')) return ;
BITMAPINFOHEADER bmiHeader;
if (file.Read((LPSTR)&bmiHeader, sizeof(bmiHeader)) != sizeof(bmiHeader))
return ;
int bmWidth = bmiHeader.biWidth;
int bmHeight = bmiHeader.biHeight;
Never consider anything impossible before trying to solve that..---Sumit Kapoor---
|
|
|
|
|