Java error in bilinear interpolation of 16 bit data

I have a problem using bilinear interpolation for 16 bit data I have two images, Orig image and display image I want to use affinetransform OP to filter origimage to displayimage through affinetransform, which is the size of the display area Origimage is of type bufferedimage TYPE_ USHORT_ Gray with sun awt. image. A grid of type shortinterleavedraster This is my current code

displayImage = new BufferedImage(getWidth(),getHeight(),origImage.getType());
try {
    op = new AffineTransformOp(atx,AffineTransformOp.TYPE_BILINEAR);
    op.filter(origImage,displayImage);
}
catch (Exception e) {
    e.printStackTrace();
}

In order to display the error, I created 2 gradient images A value with 15 bit range (32767 max) and 16 bit range (65535 max) Here are two pictures

15 bit image

16 bit image

The two images were created in the same fashion and should look the same, but notice the line in the middle of the 16 bit image At first I thought it was an overflow problem, but it was strange. It was at the center of the gradient, not at the end of the higher pixel value In addition, if this is an overflow problem, I suspect that 15 bit images will also be affected

Any help in this regard will be greatly appreciated

I just want to know why no one is answering. Did I provide enough information? Need more information?

The following is the code I use to generate affinetransform All referenced variables are calculated based on user input (mouse movement) and should be correct (it has been tested by many people, including me) I hope this will help you make mistakes

AffineTransform panTranslate = new AffineTransform();
panTranslate.translate(imagePanOffset.x,imagePanOffset.y);

AffineTransform rotateCenterTranslate = new AffineTransform();
rotateCenterTranslate.translate(imageRotateCTR.x,imageRotateCTR.y);
AffineTransform rotateTransform = new AffineTransform();
rotateTransform.rotate(Math.toradians(rotateValue));
AffineTransform rotateAntiCenterTranslate = new AffineTransform();
rotateAntiCenterTranslate.translate(-imageRotateCTR.x,-imageRotateCTR.y);

AffineTransform translateTransform = new AffineTransform();
translateTransform.translate(imageMagOffset.x,imageMagOffset.y);

AffineTransform flipMatrixTransform = new AffineTransform();

switch (flipState) {
    case ENV.FLIP_NORMAL: // NORMAL
        break;

    case ENV.FLIP_TOP_BOTTOM: // FLIP
        flipMatrixTransform.scale(1.0,-1.0);
        flipMatrixTransform.translate(0.0,-h);
        break;

    case ENV.FLIP_LEFT_RIGHT: // MIRROR
        flipMatrixTransform.scale(-1.0,1.0);
        flipMatrixTransform.translate(-w,0.0);
        break;

    case ENV.FLIP_TOP_BOTTOM_LEFT_RIGHT: // FLIP+MIRROR
        flipMatrixTransform.scale(-1.0,-1.0);
        flipMatrixTransform.translate(-w,-h);
        break;
}

scaleTransform = new AffineTransform();
scaleTransform.scale(magFactor,magFactor);

AffineTransform atx = new AffineTransform();
atx.concatenate(panTranslate);
atx.concatenate(rotateCenterTranslate);
atx.concatenate(rotateTransform);
atx.concatenate(rotateAntiCenterTranslate);
atx.concatenate(translateTransform);
atx.concatenate(flipMatrixTransform);
atx.concatenate(scaleTransform);

I still don't know what happened here I appreciate any help I can offer I also attached an example of an error in a real image I encountered for more reference

This is an error in the X-ray of the hand

This is a scaled version that focuses on the area between the thumb and the first finger

Notice again that the value in the very white area, but in the middle of the dynamic range, is like an error in a gradient image

I found more information I'm adjusting some transformations and find that if I just filter an identity matrix, this bug won't happen If I translate an integer, it won't happen If I translate with a non integer number, it will happen This also happens if I enlarge any number other than 1 (integer or non integer) I hope it helps

After more experiments, the bug is absolutely manifested in the boundary pixels between half of the maximum intensity (65535 / 2 = 32767.5) It also only occurs at this value I hope this may help diagnose!

According to alblue's requirements, here is the code completely independent of my application, which can generate errors Please note that in the original post, I included the image gradient generated using the following code, but I enlarged one of the gradients to better display the effect You should see the effect four times on 0.5 translated images, not in the other two images Also note that this error occurs for any number of zooms except 1 Just use affinetransform Getscaleinstance (0.9,0.9) replaces affinetransform Gettranslateinstance() to view the error

private static class MyJPanel extends JPanel {
    BufferedImage displayImage = null;
    public MyJPanel(double translateValue) {
        super();
        BufferedImage bi = new BufferedImage(1024,1024,BufferedImage.TYPE_USHORT_GRAY);

        int dataRange = (int)Math.pow(2,16);
        double step = dataRange/(bi.getRaster().getDataBuffer().getSize()/4.0);
        double value = 0;
        for (int i=0; i<bi.getRaster().getDataBuffer().getSize(); i++) {
            bi.getRaster().getDataBuffer().setElem(i,(int)value);
            if (value >= dataRange)
                value = 0;
            else
                value += step;
        }
        displayImage = new BufferedImage(bi.getWidth(),bi.getHeight(),bi.getType());
        AffineTransform tx = AffineTransform.getTranslateInstance(translateValue,translateValue);
        AffineTransformOp op = new AffineTransformOp(tx,AffineTransformOp.TYPE_BILINEAR);
        op.filter(bi,displayImage);
    }

    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(displayImage,this);
    }
}

private static void showDisplayError() {
    JDialog dialog1 = new JDialog();
    dialog1.setTitle("No Translation");
    MyJPanel panel1 = new MyJPanel(0);
    dialog1.getContentPane().add(panel1);
    dialog1.setSize(1024,1024);
    dialog1.setVisible(true);

    JDialog dialog2 = new JDialog();
    dialog2.setTitle("Translation of 0.5");
    MyJPanel panel2 = new MyJPanel(0.5);
    dialog2.getContentPane().add(panel2);
    dialog2.setSize(1024,1024);
    dialog2.setVisible(true);

    JDialog dialog3 = new JDialog();
    dialog3.setTitle("Translation of 1.0");
    MyJPanel panel3 = new MyJPanel(1.0);
    dialog3.getContentPane().add(panel3);
    dialog3.setSize(1024,1024);
    dialog3.setVisible(true);
}

As another update, I just tried it on Fedora 10 and saw that the bug still exists

Solution

What version of Java (Java version) and operating system do you use? It may be an error in the deformation (fixed), or it may be a rendering error to PNG

Have you tried using nearest_ Does nebbor filter replace bilinear filter?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>