java - Using JAI to rotate a grey scale image increases contrast -


I'm trying to use JAI to run the image rotation. I can not find any problem in this work, however, there is a serious shortage of midtones in the image, the picture can be rotated without the lack of contrast in Photoshop.

Please stack the 3 images given below to each other, to see what I mean;

The top image is original, it is rotated in Photoshop to prove that it can be done, and the result of my code below is

To see the real picture, please see here;

Before moving: After rotating:

You can see this problem most clearly if you load these images, two different tabs, and their Flick between.

In terms of code, I load the image in this way;

  Public Zero Test () opens the exception {file's source = new file ("C: \\ STRIP.jpg"); FileInputStream fis = New FileInputStream (source); Buffayimage source image = imageio Reed (FIS); Fis.close (); Buffer image rotated image = dotat (source image, 15); FileOutputStream Output = New FileOutputStream ("c: \\ STRIP_ROTATED.jpg"); ImageIO.write (rotated image, "JPEG", output); }  

And then here is the rotating function;

  Public Buffered Image Dorotat (Buffer Image Input, Int angle) {int width = input.getWidth (); Int height = input.getHeight (); Double radians = monastery Radian (angle / 10.0); // Rotate about the input image center AffineTransform rotate = AffineTransform.getRotateInstance (radians, width / 2.0, height / 2.0); Size rect = new rectangle (width, height); // Rotate out the image will be bigger. Rectangle border = rotate. Cut Transformed Size (Rect) .getBounds (); // Rotate image rotate between new limits. Preconnet (AffineTransform.getTranslateInstance ((widths - width) / 2.0, (bounds.height - height) / 2.0); BufferedImage output = new BufferedImage (bounds.width, bounds.height, input.getType ()); Graphics 2DG2D = (Graphics 2D) Output.Graph Graphics (); // fill the background with white g2d.setcolor (Color.WHITE); G2d.fill (new rectangle (width, height)); Rendering verses = new rendering hints (rendering hints. KEY_RENDERING, rendering hints. VALUE_RENDER_QUALITY); Signal Input (rendering signal. KEY_ANTIALAASING, rendering hints. VALUE_ANTIALIAS_ON); G2d.setRenderingHints (hint); G2d.drawImage (Input, Rotate, Blank); Return output; This is clearly a bug in JAI which has existed for a while:  

< P> It is mentioned as soon as possible that I was able to find this issue. That original article points to one, after reading that resolution, it appears that there is a root bug that is still open and

Whether all detective work is relevant to your application, it may be possible to create a color space, by default it is more tolerant that JE is using for your test code.

In the right case, you can write a pixel transcript to create rotated images. This is not optimal solution, but I mention it to perfection if you need to solve this problem today.


Comments