Return-Path: <tiff-bounces@remotesensing.org>
Received: from inav007.isp.belgacom.be (inav007.isp.belgacom.be [195.238.2.76])
        by mailst035.isp.belgacom.be (8.12.11/8.12.11/Skynet-MAILSTORE-2.14) with ESMTP id iAM6W3qv015016
        for <joris.at.lebbeke@skynet.be>; Mon, 22 Nov 2004 07:32:03 +0100
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from inas011.isp.belgacom.be (localhost [127.0.0.1])
        by inav007.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AV-3.00) with ESMTP id iAM6VsYd016336
        for <joris.at.lebbeke@skynet.be>; Mon, 22 Nov 2004 07:31:54 +0100
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from inmx015.isp.belgacom.be (inmx015.isp.belgacom.be [195.238.2.218])
        by inas011.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AS-2.03) with ESMTP id iAM6Vmom026994
        for <joris.at.lebbeke@skynet.be>; Mon, 22 Nov 2004 07:31:49 +0100
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from xserve.flids.com (adsl-065-083-169-202.sip.mco.bellsouth.net [65.83.169.202])
        by inmx015.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-2.32) with ESMTP id iAM6Va2D023616
        for <joris.at.lebbeke@skynet.be>; Mon, 22 Nov 2004 07:31:38 +0100
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from adsl-065-083-169-202.sip.mco.bellsouth.net (localhost [127.0.0.1])
	by xserve.flids.com (Postfix) with ESMTP
	id 5E03C49528B; Mon, 22 Nov 2004 01:31:20 -0500 (EST)
X-Original-To: tiff@remotesensing.org
Delivered-To: tiff@remotesensing.org
Received: from mirapoint1.tis.cwru.edu (mirapoint1.tis.cwru.edu
	[129.22.104.46])
	by xserve.flids.com (Postfix) with ESMTP id E1E51495276
	for <tiff@remotesensing.org>; Mon, 22 Nov 2004 01:31:18 -0500 (EST)
Received: from sublimity13 (204-212-236-197.tv.blacksburg.ntc-com.net
	[204.212.236.197]) by mirapoint1.tis.cwru.edu (MOS 3.5.4-GR)
	with ESMTP id DFM60635 (AUTH zwb2);
	Mon, 22 Nov 2004 01:30:53 -0500 (EST)
From: "Zac Bond" <zacwbond@vt.edu>
To: <tiff@remotesensing.org>
Date: Mon, 22 Nov 2004 01:32:47 -0500
Message-ID: <NHBBJGKPALDKGHGBHEPAGENICMAA.zacwbond@vt.edu>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
Subject: [Tiff] Unexpected TIFF output
X-BeenThere: tiff@remotesensing.org
X-Mailman-Version: 2.1.2
Precedence: list
List-Id: TIFF and libtiff discussion  <tiff.remotesensing.org>
List-Unsubscribe: <http://xserve.flids.com/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=unsubscribe>
List-Archive: <http://xserve.flids.com/pipermail/tiff>
List-Post: <mailto:tiff@remotesensing.org>
List-Help: <mailto:tiff-request@remotesensing.org?subject=help>
List-Subscribe: <http://xserve.flids.com/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=subscribe>
Sender: tiff-bounces@remotesensing.org
Errors-To: tiff-bounces@remotesensing.org
X-UIDL: cebf49166340720e60d30d2d8510fa92

I am attempting to write a program that extracts text from an old
document based on the color of the ink.  I am having a lot of trouble
figuring out how to use libTIFF to write my image to a file.   Here
are the results:

Original: http://home.cwru.edu/~zwb2/smallblock.tif
Result:   http://home.cwru.edu/~zwb2/binresult.tif

As you can see, the second image looks like a squashed version of part
of the original, with odd vetical lines.  I don't understand how this
is happening; the contents of my image buffer are correct.  Also, I
notice that the output has only values of 255 and 0, whereas my buffer
used 250 and 10.  Huh?

Here is my code.  I'm guesing I am using TIFFWriteScanline wrong, or
else perhaps I forgot to set an important tag?
(I deleted the errorchecking for this post, but there were no errors
when run)

int main(int argc, char* argv[])
{
	// Open file
	TIFF* infile = TIFFOpen(argv[1], "r");

	// Read in tags
	uint32 rows, columns;
	size_t imagesize;
	int errorval;

	TIFFGetField(infile, TIFFTAG_IMAGELENGTH, &rows);
	TIFFGetField(infile, TIFFTAG_IMAGEWIDTH, &columns);

	// Now we read in the color image using RGBA
	imagesize = rows * columns;
	uint32* raster = (uint32*) _TIFFmalloc(imagesize * sizeof(uint32));
	TIFFReadRGBAImageOriented(infile, columns, rows, 									raster,
ORIENTATION_TOPLEFT, 1);

    	// Now create an output file & set fields for an 8-bit grayscale
image
	TIFF* outfile = TIFFOpen("binresult.tif", "w");
	TIFFSetField(outfile, TIFFTAG_IMAGELENGTH, rows);
	TIFFSetField(outfile, TIFFTAG_IMAGEWIDTH, columns);
	TIFFSetField(outfile, TIFFTAG_BITSPERSAMPLE, 8);
	TIFFSetField(outfile, TIFFTAG_COMPRESSION, 1);
	TIFFSetField(outfile, TIFFTAG_FILLORDER, 1);
	TIFFSetField(outfile, TIFFTAG_ORIENTATION, 1);
	TIFFSetField(outfile, TIFFTAG_PHOTOMETRIC, 1);
	TIFFSetField(outfile, TIFFTAG_PLANARCONFIG, 1);
	TIFFSetField(outfile, TIFFTAG_SAMPLESPERPIXEL, 1);

	// Allocate memory the new image
	uint32* binimage = (uint32*) _TIFFmalloc(imagesize * sizeof(uint32));

	for (int r = 0; r < rows; r++)
		for (int c = 0; c < columns; c++)
		{
			// Various logic to threshold the image
			// based on pixel color goes on in here
			if (fill_loc)
				binimage[r * columns + c] = 10;
			else
				binimage[r * columns + c] = 250;
		}

	// Write the new file
	for (int r = 0; r < rows; r++)
          TIFFWriteScanline(outfile, &binimage[r * columns], r);

	// Clean up memory, etc.
}

Thanks to anyone who can help me out.  I'm a bit new to this, and I'm
sure I'm missing something simple.

-Zac Bod

_______________________________________________
Tiff mailing list
Tiff@remotesensing.org
http://xserve.flids.com/mailman/listinfo/tiff
