Bilinear interpolation on single pixels

Hi friends,
Could I ask a question about Bilinear interpolation on grayscale pixels.
I scanned Point2D in a triangle on a grayscale image.
Then I used PerspectiveTransform to get pixel position in target triangle.
Now I am trying to use bilinear interpolation to get color of each pixels.
If someone can help me with this, I would appreciate a lot.
My code is below, However it dose not work properly.
protected int biLinear(Point2D srcPt,Point2D trgPt) {
          if(((int)srcPt.getX()==(image.getWidth()-1))||((int)srcPt.getY()==(image.getHeight()-1))){
               int gD00 = image.getRaster().getSample((int)srcPt.getX(), (int)srcPt.getY(),0);
               int c = createPixelInt(gD00,gD00,gD00);
               return c;
          else{
               float px = (float)trgPt.getX();
               float py = (float)trgPt.getY();
               float p = px - (int)px;
               float q = py - (int)py;
               int d00 = image.getRaster().getSample((int)srcPt.getX(), (int)srcPt.getY(),0);
               //int d00 = createPixelInt(gD00,gD00,gD00);
               int d01 = image.getRaster().getSample((int)srcPt.getX(), (int)srcPt.getY()+1,0);
               //int d01 = createPixelInt(gD01,gD01,gD01);
               //int test = (int)srcPt.getX()+1;
               //System.out.println(test);
               int d10 = image.getRaster().getSample((int)srcPt.getX()+1, (int)srcPt.getY(),0);
               //int d10 = createPixelInt(gD10,gD10,gD10);
               int d11 = image.getRaster().getSample((int)srcPt.getX()+1, (int)srcPt.getY()+1,0);
               //int d11 = createPixelInt(gD11,gD11,gD11);
               int c = (int)((1-q)*( (1-p)*d00+p*d01 ) + q*( (1-p)*d10+p*d11 ));
               return c;
private int createPixelInt(int r, int g, int b) {
         return (b&0x000000ff) | ((g<<8)&0x0000ff00) | ((r<<16)&0x00ff0000)
                | (0xff000000);
     }

Sirian_ye wrote:
..My code is below,For better help sooner, post an SSCCE *(<- link)* rather than uncompilable code snippets.
Two further points about code samples:
- For image based SSCCEs, either hot-link to an image available off the internet, or generate one in the code. It is fairly easy to create a BufferedImage using a GrapientPaint that goes from white on one corner, to black in the opposite corner.
- Use meaningful attribute names so that people have a hope of following what is happening.
.. However it dose not work properly. When code does not work as you expect, try to define precisely:
1) What it is you expected.
2) How the result differed from that expectation.

Similar Messages

  • JS/PS CS3: identify single pixels sticking out

    In a bitmap, is it possible to identify single pixels sticking out from a shape? Let's say I have this black shape in a black-and-white bitmap:
       xxxxxxxx
       xxxxxxxx
       xxxxxxxx
       xxxxxxxx
            x
    an 8 by 4 rectangle with one pixel sticking out from the bottom. Question is, can I find such pixels using a script (JS) and make it white?
    Thanks,
    Peter

    Peter, I added the work around to the script. It appears to fix the problem. With my basic test files.
    #target photoshop
    app.bringToFront();
    while (app.documents.length) {
      app.activeDocument.close(SaveOptions.PROMPTTOSAVECHANGES);
    var defaultFolder = new Folder ('~/Desktop');
    var inputFolder = defaultFolder.selectDlg('Please select your Folder of Bitmap files…');
    var outputFolder = defaultFolder.selectDlg('Please Make/Select a Folder to save Cleaned up files to…');
    if (inputFolder != null && outputFolder != null) {
    var fileList = inputFolder.getFiles(fileFiltering);
    if (fileList.length > 0) {
    main(fileList);
    } else {
    alert('This Folder contained NO Photoshop Tiff files!');
    } else {
    alert('A Required folder was NOT chosen!!!');
    // Main Photoshop file processing
    function main(fileObjs) {
    with (app) {
    var whiteRef = new SolidColor();
    whiteRef.rgb.red = 255;
    whiteRef.rgb.green = 255;
    whiteRef.rgb.blue = 255;
    backgroundColor = whiteRef; // This will be used with resizeCanvas(+)
    var userDisplayDialogs = displayDialogs;
    var userRulerUnits = preferences.rulerUnits;
    displayDialogs = DialogModes.NO;
    preferences.rulerUnits = Units.PIXELS;
    for (var i = 0; i < fileObjs.length; i++) {
    if (fileList[i] instanceof File) {
    open(fileObjs[i]);
    var docRef = activeDocument;
    with (docRef) {
    var baseName = app.activeDocument.name.slice(0, -4);
    if (mode != DocumentMode.GRAYSCALE) changeMode(ChangeMode.GRAYSCALE);
    docRes = resolution;
    resizeCanvas(width + 4, height + 4, AnchorPosition.MIDDLECENTER);
    // Cleans single pixels
    artLayers[0].applyMaximum(1); // Adjust as required
    artLayers[0].applyMinimum(1); // Ditto
    artLayers[0].invert();
    artLayers[0].applyMaximum(1); // Ditto
    artLayers[0].applyMinimum(1); // Ditto
    artLayers[0].invert();
    resizeCanvas(width - 4, height - 4, AnchorPosition.MIDDLECENTER);
    var thisBitmap = bitmapOptions(docRes)
    changeMode(ChangeMode.BITMAP, thisBitmap);
    var newFilePath = new File(outputFolder + '/' + baseName + '.tif');
            SaveFileasTIFF(newFilePath, false, TIFFEncoding.TIFFLZW, false, false, false);
            close(SaveOptions.DONOTSAVECHANGES);
    displayDialogs = userDisplayDialogs;
    preferences.rulerUnits = userRulerUnits;
    function bitmapOptions(res) {
      bitOptions = new BitmapConversionOptions();
    //bitOptions.angle = 0;
    //bitOptions.frequency = 150;
    bitOptions.method = BitmapConversionType.HALFTHRESHOLD;
    //bitOptions.pattenName = '';
    bitOptions.resolution = res;
    bitOptions.shape = BitmapHalfToneType.SQUARE;
    return bitOptions;
    function SaveFileasTIFF(saveFile, aC, iC, la, sC, tr) {
      tiffSaveOptions = new TiffSaveOptions();
      tiffSaveOptions.alphaChannels = aC;
      tiffSaveOptions.byteOrder = ByteOrder.MACOS;
      tiffSaveOptions.embedColorProfile = true;
      tiffSaveOptions.imageCompression = iC;
      tiffSaveOptions.layers = la;
      tiffSaveOptions.spotColors = sC;
      tiffSaveOptions.transparency = tr;
      activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
    // Mac ONLY filtering (Photoshop Tiff's)
    function fileFiltering(fileObj) {
    if (fileObj.creator == '8BIM' && fileObj.type == 'TIFF') {
    return true;
    } else {
    return false;

  • How to copy and paste a single pixel

    How to copy and paste a single pixel
    I want to copy a single pixel and then paste it in the
    position of
    another pixel in the same image.
    (This is in effect changing the colour of the target pixel,
    isn't it.
    But in my case copying an existing pixel seems simpler than
    selecting a
    colour from the swatch or using the colour picker.)
    What is the most efficient way of doing this?
    I tried to select one pixel with the marquee tool. Then
    copied it with
    control-C, but then how do I select the target pixel and
    paste with
    control-V?
    Thanks for your help.
    Adrian

    Use the Pencil Tool
    alex
    adrian stock wrote:
    > How to copy and paste a single pixel
    >
    > I want to copy a single pixel and then paste it in the
    position of
    > another pixel in the same image.
    >
    > (This is in effect changing the colour of the target
    pixel, isn't it.
    > But in my case copying an existing pixel seems simpler
    than selecting a
    > colour from the swatch or using the colour picker.)
    >
    > What is the most efficient way of doing this?
    >
    > I tried to select one pixel with the marquee tool. Then
    copied it with
    > control-C, but then how do I select the target pixel and
    paste with
    > control-V?
    >
    > Thanks for your help.
    >
    > Adrian
    >

  • I have a single Pixel that is broke on my 2 month old retina macbook pro. I have Apple care. What will Happen if I bring it to an apple store.

    I have a single Pixel that is broke on my 2 month old retina macbook pro. I have Apple care. What will Happen if I bring it to an apple store.

    You can try to see if they will replace it, however there is some sort of acceptable amount of stuck pixels and they won't replace so I hear.
    But that was a long time ago and things change.

  • How to fill or erase a single pixel?

    What tool or tools do I have to use to erase or fill a single pixel at a time?
    Sincere thanks in advance for yourhelp.
    Al

    So many ways; you can use one or a combination of:
    Brush Tool set to 1 pixel and a color that matches the area
    Spot Healing Brush Tool set to around 3 or 4 pixels
    Clone Stamp Tool set to a reasonable size based upon area and a soft edge (a graphics tablet like those from Wacom is a big help here due to being able to set size and opacity; pen pressure determines size and/or opacity as you paint)

  • Cropping problem: crops to a single pixel

    I select part of the image using the crop tool, but when I execute the crop, the result is a single pixel, regardless of the size of the cropping box

    reset the values in the options bar. You will find they are set to 1. CS3 has a mysterious tendency to do this on its own.

  • How to add Event to every single pixel with BitmapData?

    What I want to accomplish: when I drag the cursor over a sprite I want the sprite to break down and every single pixel moves through the screen at random x and y axis.
    To make it simple the draw this is what I want but with much more fragments(pixels) around, thousands of them. How come could I approach this?
    Thanks in advance.

    if mc is the object whose pixels you want to randomize and display in a bitmap:
    var bmpd:BitmapData = new BitmapData(mc.width,mc.height);
    bmpd.draw(mc);
    var bmp:Bitmap = new Bitmap(bmpd);
    addChild(bmp);
    mc.visible=false;
    mc.addEventListener(MouseEvent.MOUSE_OVER,randomizeF);
    function randomizeF():void{
        var a:Array = [];
        for(var x:int=1;x<=bmpd.width;x++){
            for(var y:int=1;y<=bmpd.height;y++){
                a.push(bmpd.getPixel32(x,y));
        shuffle(a);
        var i:int=0;
        for(x=1;x<=bmpd.width;x++){
            for(y=1;y<=bmpd.height;y++){
                bmpd.setPixel32(x,y,a[i]);
                i++;
    function shuffle(a:Array) {
        var p:int;
        var t:*;
        var ivar:int;
        for (ivar = a.length-1; ivar>=0; ivar--) {
            p=Math.floor((ivar+1)*Math.random());
            t = a[ivar];
            a[ivar] = a[p];
            a[p] = t;

  • CS4 GL Settings; Force Bilinear Interpolation?

    My graphic cards are Nvidia GeForce 7300 GT and I have "Enable OpenGL Drawing" activated in CS4 and in the advanced settings, the default is Vertical Sync checked and Force Bilinear Interpolation is unchecked.
    What exactly is "Force Bilinear Interpolation" and what advantage (if any) is there to turning it on?

    The way I read that passage left me with an impression that there were more calculations required in Bilinear Interpolation and I would expect a slower redraw. LOL Go figure. Maybe someone who actually knows something will add to this thread.

  • Possible to paint single pixel?

    The Graphics class has methods to paint different object eg.:
    drawOval(int x, int y, int width, int height)
    but is it possible to paint just one pixel?

    fillRect() can be used for that.Although it should be noted that drawLine() is faster. Of course, knowing that is only useful if you're drawing lots of single pixels.

  • Just a single pixel.

    I can't find a method in graphics or ghraphics2d that will allow me to change a single pixel in the paintComponent method. the best I can do is a very short line (g.drawLine(x, y, x, y)). surely a method like this would call a method that draws a dot, but I can't find it. a little help please.

    This is just my 2 cents.
    somebody must know more about the 'graphics' class,
    and how the drawLine method is programmed - it must,
    itself, draw one pixel at a time.Well, maybe not. A Java implementation does not talk to the hardware. It will generally have to call some native method that calls a 3rd party graphics implementation (X, WinG, Direct Draw, etc. ), which in turn could call another level of abstraction... including the driver and eventually hardware. There's no guarantee that a 3rd pary API or interface will have a "drawPoint(x,y)" method on ever conceivable OS and graphics configuration. Furthermore it might be the case that a particular optimization occurs in the hardware level. Maybe some graphics hardware is only capable of drawing "lines" even if they are only 1 pixel long. Certainly hardware accellerated 2d and 3d graphics aren't drawn 1 pixel at a time at the software level. It makes sense that a filled rectangle should be done at hardware level, probably evel lines.
    Probably the most overhead here is putting 2 extra values on the call stack.
    Anyway, I think the old saying about premature optimization is as true here as it is otherwise. If you can actually show with the use of a profiler that an application's bottleneck is the Graphics.drawLine method, and that there's no more efficient way to write the app, THEN we have a problem.
    Or satisfy your curiosity:
    public static void main(String[] args)
            int trials = 30;
            int loops = 20000000;
            long cummulative_2parms = 0;
            long cummulative_4parms = 0;
            for (int i=0; i<trials; i++)
                long t;
                //2 parms
                t = -System.currentTimeMillis();
                for (int j=0; j<loops; j++)
                    two_parms(j, j);
                t+= System.currentTimeMillis();
                cummulative_2parms +=t;
                System.out.println(
                        "2 parm ms:  " + t + "\n" +
                        "cummulative " + cummulative_2parms + "\n");
                //4 parms
                t = -System.currentTimeMillis();
                for (int j=0; j<loops; j++)
                    four_parms(j, j, j, j);
                t+= System.currentTimeMillis();
                cummulative_4parms +=t;
                System.out.println(
                        "4 parm ms:  " + t + "\n" +
                        "cummulative " + cummulative_4parms + "\n");
        static void two_parms(int x, int y)
        static void four_parms(int i01, int i02, int i03, int i04)
        }

  • Single pixel vertical line

    Suddenly there's a single pixel white vertical line smack down the center of my screen, always there no matter how I boot up the computer. Any suggestions?

    Any suggestions?
    Take it in for repair.

  • Color problems using bilinear interpolation with AffineTransformOp

    I am trying to apply AffineTransformOp's to BufferedImage's and it seems if I use TYPE_BILINEAR interpolation, the colors of the resulting images are messed up.
    This example program loads each .jpg in the current directory, applies an identity transformation using each of two interpolation methods, and saves the results to (different) filenames. Give it a try with any color .jpg and you should see this problem.
    import java.awt.geom.AffineTransform;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    public class InterpolateProblem {
         * Read in every .jpg in current directory, apply identity transform using two
         * different interpolation methods, save results.
         public static void main(String[] args) throws IOException {
              String[] files = new File(System.getProperty("user.dir")).list();
              String prefix = "CVT";
              for (int i = 0; i < files.length; i++) {
                   String name = files;
                   File src = new File(name);
                   if (!src.isFile() || !name.endsWith(".jpg") || name.startsWith(prefix))
                        continue;
                   // Read original .jpg
                   BufferedImage orig = ImageIO.read(src);
                   // Construct identity transformation
                   AffineTransform tx = new AffineTransform();
                   // Apply transformation using NEAREST_NEIGHBOR, write results to CVT1_xxx
                   File dest1 = new File(src.getParent(), prefix + "1_" + src.getName());
                   AffineTransformOp op1 = new AffineTransformOp(tx,
                             AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
                   ImageIO.write(op1.filter(orig, null), "jpeg", dest1);
                   // Apply transformation using BILINEAR, write results to CVT2_xxx
                   File dest2 = new File(src.getParent(), prefix + "2_" + src.getName());
                   AffineTransformOp op2 = new AffineTransformOp(tx,
                             AffineTransformOp.TYPE_BILINEAR);
                   ImageIO.write(op2.filter(orig, null), "jpeg", dest2);

    >Odd how it could look fine with windows and others but really off with LR.
    None of the others typically color manage, so they don't use the profile. Also, a large number of the icc profiles that are shipped with display drivers for windows ar corrupt out of the box (really strange but true) so you're usually better off just deleting them. That said, if you want good color you basically have to actually calibrate. Using sRGB is a very bad alternative. You need to calibrate using real calibration hardware for good color and use color managed apps wherever you can (Lightroom, Photoshop, Safari, Firefox with the secret setting enabled, but NOT internet explorer or windows picture viewer. They never show you the actual color.

  • Make a single pixel vertical column

    I have a 1024x768 canvas and I want to draw two 1 pixel columns, one starting in column 0 and one in column 1023 (basically two tall white strips on the far left and far right)
    how can I make this as a png which is transparent in the middle.  I need to put this on top of another image and cover the left and right edges.
    Is this possible with photoshop?

    New Document: 1024 x768
    New Layer
    Click and hold on the Rectangular Marquee. Choose the Single Column Marquee Tool (vertical)
    Click and hold anywhere in the document - drag cursor to upper left (even beyond) Let go of mouse.
    Hold shift key down and repeat on right side.
    Pres the D key to reset swatches.
    Command Delete / Control Backspace (PC)
    Hide background layer.
    Save for Web and Devices - Choose PNG 24. Save.
    Here: Right click and save this file.

  • Forcing Acrobat to display a PDF with an accuracy of a single pixel

    This is a bit strange question, I didn't know where to put it...
    I'm developing a program for creating a pdf from a GUI interface sample.
    This means that I need to replicate what is in the GUI to the PDF EXACTLY. And when I say that I mean to the pixel.
    Windows magnifier tool helps a lot, however, Acrobat (as Reader as well) does not draw everything to a pixel. It's not only due to the Acrobat, but drivers and some screen and display setting as well. That can't be helped. However, if I zoom in enough everything will be shown properly, but the bounds of the original pixels will be distorted...
    Is there any way I can zoom in and somehow see where each pixel should be?

    You can turn off smoothing in options, but that's about it. If the zoom factor is right AND of course if you make sure not to use lossy compression on the screen shots, then you should see a screen shot pretty much as the original screen.

  • Single pixel formation in Intensity graph

    I needed to capture a image using CCD camera. Though it has 16 bit resolution, i need to focus on ONE PIXEL.
    The process goes like this. Save the image information in a spread sheet array and then find the max value of the array. Till this step, i am OK.
    But how do i get to display this MAX value using intensity graph??
    Intensity graph is 2D array which needs X and Y value.
    So I need to get the X and Y value of the max value of array. I tried using the max index value of 'Max and Min' array function. But it is of no use since the value comes as 1Dimension but the intensity graph needs 2D information in the form of X and Y value. 
    Please help me on this. Thanks in advance.

    Asking the same question in multiple threads does not help or get you an answer more quickly.  Please be patient.  Many of us who participate in the Forum do so as volunteers.
    Now to your question.  As you noted, you can use the Array Max & Min function to locate a pixel with the maximum value.  If more than one pixel has that value, this function only reports the first occurrence of that value.  The 1D output of the Array Max & Min function contains the indexes of the pixel.  So the first element would be the row index (X value) and the second element would be the column index (Y value).   What I do not understand is why you want to display just one value on an intensity graph.  That seems rather meaningless.  Please explain what you want the output to look like.
    Lynn

Maybe you are looking for

  • Toshiba Satellite p75-A7200 stuck on toshiba logo after bios change

    My Toshiba Satellite p75-A7200 is stuck on toshiba logo after bios change. entered bios fine changes from UEFI to CSM boot and now i cannot enter bios or boot past toshiba logo. Ive tried F2 tapping and holding while powering up the laptop(tried ever

  • Excise capturing without base value

    Dear CIN Gurus, There is a very specific scenario for which I need your help. We have Lump Sum Turnkey Contracts where the vendor gives a ceiling excise amount for which he will give the excise invoice. This ceiling excise amount has no base value on

  • Connecting two WRV200's to share same wireless and wired network

    I am looking at purchasing a second WRV200.  I want to have both wired together on the same network along with having them include the wireless on both to the same network. i.e. having two wired locations and two wireless AP's to get on to the one ne

  • My iTunes account has been disabled how do i enable it

    my itunes account has been diabled and i need hel enabling it?

  • How to Make Gmail the default mailto: link

    I need help. I would like to make gmail my default mailto provider in Safari.  Gmail Notifier used to take care of this, but since Google removed that program, I haven't figured out a way to do it. Right now, Safari will start the Mail app when I wan