tags:

views:

373

answers:

2

Hi,

Let's say i have a 100000x100000 1 bit (K channel) tiff with a dpi of 2000 and i want to downscale this to a dpi of 200. My resulting image would be 10000x10000 image. Does this mean that every 10 bits in the 1 bit image correspond to 1 pixel in the new image? By the way, i am using libtiff and reading the 1 bit tiff with tiffreadscanline. Thanks!

A: 

That means every 100 bits in the 1 bit image correspond to 1 pixel in the new image. You'd need to average the value over 10x10 1bit pixel area. For smoother greyscales, you'd better average over n bits where n is the bit depth of your target pixel, overlying the calculated area partially with neighbor areas (16x16px squares 10x10px apart, so their borders overlay, for a smooth 8-bit grayscale.)

SF.
Keep in mind, though, that this blurs the image in addition to downsampling.
Joey
With 1.3px blur radius the effect will probably add to (subjective) quality rather than reduce it, and I found upscaling from 100 to 256 grayscale levels by a simple lookup looks really ugly in gradient areas of the image.
SF.
correction: 0.8px blur radius.
SF.
I just tried my own experiment with both a 5x5 and 7x7 averaging blur, followed by a 5:1 downsample. The one with the 7x7 blur was much nicer than the other. I'm not sure I would base the factor on the bit depth of the target though.
Mark Ransom
A: 

It is important to understand why you want to downscale (because of output medium or because of file size?). As SF pointed out, colors/grayscale are somewhat interchangeable with resolution. If it is only about file size losless/lossy compression is also worth to look at..

The other thing is to understand a bit of the characteristics of your source image. For instance, if the source image is rasterized (as for newspaper images) you may get akward patterns because the dot-matrix is messed up. I have once tried to restore an old news-paper image, and I found it a lot of work. I ended up converting it to gray scale first before enhancing the image.

I suggest to experiment a bit with VIPS or Irfanview to find the best results (i.e. what is the effect of a certain resampling algorithm on your image quality). The reason for these programs (over i.e. Photoshop) is that you can experiment with GUI/command line while being aware of name/parameters of the algorithms behind it. With VIPS you can control most if not all parameters.

[Edit] TiffDump (supplied with LibTiff binaries) is a valuable source of information. It will tell you about byte ordering etc. What I did was to start with a known image. For instance, LibTIFF.NET comes with many test images, including b&w (some with 0=black, some with 1=black). [/Edit]

Adriaan
Actually my current problem now is interpreting bits in the 1-bit image.say i have 200x144 pix 1 bit image and i just want to convert it to a 200x144 pix 8 bit image,whereas my mapping would be 1-bit's 0 is 255 (gray) and 1-bit's 1 is 0 (gray). on a 1-bit image tiffreadscanline i get the following bits:0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00i only get 25 bits but the 1-bit image's width is 200. so i expect a scan line size of 200 also.if i multiply 25 by 8 i get 200 but where would i get data? thanks.
You get 25 bytes 8 bits each for a total of 200 bits=pixels.By increasing the depth to 8bit you will waste 7 bits in a byte of the resulting image.It's up to you (using bit shift, masks and logical operators) to extract a single bit from the byte.
SF.
I agree with SF. Please see my [Edit] in my post.
Adriaan
Use a libtiff derivate... GDI+ TIFF handling is horrible in Windows XP. Windows 7 seems to do a much better job. From C#.NET you see a mysterious error on XP whereas the Windows7 call will work as expected.
Adriaan