sprhawk / leptonica

Automatically exported from code.google.com/p/leptonica
0 stars 0 forks source link

The output of pixScale and pixRotate is distorted for 1bpp images #95

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try to load the attached image input.pbm using PIX* pixs = 
pixRead("input.pbm")
2. Call PIX* pixd = pixRotate90(pixs,1) or PIX *pid = pixScale(pixs,3.0,3.0) to 
rotate or zoom the image
3. Use pixWrite("zoomed.pbm",pixd,IFF_PNM) to write the resultant image to the 
disk. The output file is not a proper zoomed or rotated version, but a 
distorted version.

What is the expected output? What do you see instead?
The zoomed/rotated images should be OK

What version of the product are you using? On what operating system?
Leptonica 1.70 on Ubuntu 13.04 (INTEL)

Please provide any additional information below.

I have verified that the reading of PIX from the image is OK. The result is OK 
if the Zoom factor is set to 1, where in it simply copies pixs to pixd 
internally.

I have attached the images and the source code for reference.

Original issue reported on code.google.com by saa...@gmail.com on 20 May 2014 at 9:12

Attachments:

GoogleCodeExporter commented 9 years ago
Your zoomed and rotated images are corrupted.  I have never seen this.  The 
problem is not with the leptonica library.

I ran this:
    pix1 = pixRead("input.pbm");
    pix2 = pixScale(pix1, 0.6, 0.6);
    pix3 = pixRotate90(pix1, 1);
    pixWrite("junk.scaled.pnm", pix2, IFF_PNM);
    pixWrite("junk.rot.pnm", pix3, IFF_PNM);
    pixDisplay(pix1, 0, 100);
    pixDisplay(pix2, 500, 100);
    pixDisplay(pix3, 1000, 100);

and got properly scaled and rotated images (attached).

Suggest that you display the pix to see if they were corrupted in memory before 
writing them out.

Also suggest you go to leptonica.org and download 1.71.

Original comment by dan.bloo...@gmail.com on 20 May 2014 at 4:08

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The below flags were defined in our Makefile while compiling Leptonica,
-fPIC
-DL_BIG_ENDIAN

If the second flag is not used during compilation, the 8bpp Gray images have 
their bytes swapped out. Any idea why it is so?

>>Also suggest you go to leptonica.org and download 1.71.
It is still not available at http://www.leptonica.org/download.html

Original comment by saa...@gmail.com on 21 May 2014 at 6:54

GoogleCodeExporter commented 9 years ago
You're right about 1.71.  Still not up.

Is your hardware big-endian?

Do the zoomed/rotated images look OK with pixDisplay?

Is there byte-swapping when you output in png or bmp?

Original comment by dan.bloo...@gmail.com on 21 May 2014 at 2:38

GoogleCodeExporter commented 9 years ago
>>Is your hardware big-endian?
My hardware is not Big Endian. It was an old PowerPC Makefile, which was 
blindly used even while compiling for Intel. 
However, when the flag (-DL_BIG_ENDIAN) is removed, the PIX data was byte 
swapped in case of 8bpp images. I confirmed this by creating a pgm/pbm file and 
comparing the hexdump. 

>>Is there byte-swapping when you output in png or bmp?
I have checked it for png and pgm but not for bmp.

>>Do the zoomed/rotated images look OK with pixDisplay?
No, when I removed the flag, the output from pixDisplay() was NG.
I have now removed the flag and added pixEndianByteSwap() every time I read an 
image (pbm, png, RAW). With this change, the behaviour is OK for both 8bpp and 
1bpp images.

Still not sure why byte swapping is happening. But, surprisingly it works 
perefectly fine with RGB images. 
I am compiling on a Ubuntu 13.04 Virtual machine. Does it make any difference?

Original comment by saa...@gmail.com on 21 May 2014 at 5:12

GoogleCodeExporter commented 9 years ago
Sorry you've had so much trouble with the endian settings.

Since your hardware is little-endian, try using either the automake makefile or 
the static ones that I provide with 1.70.  

If you want to use the static makefiles, after you download, type 
make-for-local to rename, check which I/O libraries you have and get them set 
properly in environ.h, and then type make in src.  You can add new targets to 
the prog/makefile for your specific applications.   See the README.html for 
details.

Original comment by dan.bloo...@gmail.com on 21 May 2014 at 6:18

GoogleCodeExporter commented 9 years ago
Thanks a ton for the quick response!!
I will go through README.html, make the necessary changes and share my 
observations.

Original comment by saa...@gmail.com on 21 May 2014 at 7:08