Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default How to make a morph Method

    I am trying to make a method in a picture class that morphs 1 photo into another, over a certain amount of frames i can choose using this formula
    colorValue = startValue = ((endValue - startValue)4*k


    here is what i have so far and its not working and im getting frustrated.

    public void morphStage(Picture startPicture, Picture endPicture, int numStages, int k)
    {
    Pixel[] pixelArrayStart = startPicture.getPixels();
    Pixel[] pixelArrayEnd = endPicture.getPixels();
    Pixel[][][] pixelRGB = null;
    Pixel pixelObjEnd = null;
    Pixel pixelObjStart = null;


    //***********************Colour Values for Start Photo *************************************
    int redValueStart = 0;
    int greenValueStart = 0;
    int blueValueStart = 0;
    //********************* Colour Values for End Photo ****************************************
    int redValueEnd = 0;
    int greenValueEnd = 0;
    int blueValueEnd = 0;
    //**********************Colour Values for intermediate photo********************************
    int redValue = 0;
    int greenValue = 0;
    int blueValue = 0;
    //////////////////////////////////////////////////////////////////////////////////////////////////


    for(int y = 0; y < getHeight(); )//loops colums
    {
    for(int x =0; x < getWidth(); )//loops rows
    {
    //Gets the pixel and the color of that pixel
    pixelObjStart = this.getPixel(x,y);
    redValueStart = pixelObjStart.getRed();
    greenValueStart = pixelObjStart.getGreen();
    blueValueStart = pixelObjStart.getBlue();
    pixelObjEnd = this.getPixel(x,y);
    redValueEnd = pixelObjEnd.getRed();
    greenValueEnd = pixelObjEnd.getGreen();
    blueValueEnd = pixelObjEnd.getBlue();


    for(int i = 0; i < pixelArrayStart.length; )//Morhphing loop
    {
    pixelObjStart = pixelArrayStart[i];
    redValue = redValueStart +((redValueEnd - redValueStart)/(numStages + 1))*k;
    greenValue = greenValueStart +((greenValueEnd - greenValueStart)/(numStages + 1))*k;
    blueValue = blueValueStart +((blueValueEnd - blueValueStart)/(numStages + 1))*k;

    pixelObjStart.setRed(redValue);
    pixelObjStart.setGreen(greenValue);
    pixelObjStart.setBlue(blueValue);


    x++;
    y++;
    i++;
    }
    }
    }
    }


    any help would be great.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default

    Your code uses Picture and Pixel classes which are not part of the standard JDK and about which we know nothing except the names. If you wrote those classes, post the code here. If you got them from somewhere else, that's the place to ask for help.

    db

  3. #3
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.text.*;

    /**
    * A class that represents a picture. This class inherits from
    * SimplePicture and allows the student to add functionality to
    * the Picture class.
    *
    * Copyright Georgia Institute of Technology 2004-2005
    * @author Barbara Ericson ericson@cc.gatech.edu
    */
    public class Picture3darraay extends SimplePicture
    {
    ///////////////////// constructors //////////////////////////////////

    /**
    * Constructor that takes no arguments
    */
    public Picture3darraay ()
    {
    /* not needed but use it to show students the implicit call to super()
    * child constructors always call a parent constructor
    */
    super();
    }

    /**
    * Constructor that takes a file name and creates the picture
    * @param fileName the name of the file to create the picture from
    */
    public Picture3darraay(String fileName)
    {
    // let the parent class handle this fileName
    super(fileName);
    }

    /**
    * Constructor that takes the width and height
    * @param width the width of the desired picture
    * @param height the height of the desired picture
    */
    public Picture3darraay(int width, int height)
    {
    // let the parent class handle this width and height
    super(width,height);
    }

    /**
    * Constructor that takes a picture and creates a
    * copy of that picture
    */
    public Picture3darraay(Picture copyPicture)
    {
    // let the parent class do the copy
    super(copyPicture);
    }

    ////////////////////// methods ///////////////////////////////////////

    /**
    * Method to return a string with information about this picture.
    * @return a string with information about the picture such as fileName,
    * height and width.
    */
    public String toString()
    {
    String output = "Picture, filename " + getFileName() +
    " height " + getHeight()
    + " width " + getWidth();
    return output;

    }
    //MorphStage method
    public void morphStage(Picture startPicture, Picture endPicture, int numStages, int k)
    {
    Pixel[] pixelArrayStart = startPicture.getPixels();
    Pixel[] pixelArrayEnd = endPicture.getPixels();
    Pixel pixelObjEnd = null;
    Pixel pixelObjStart = null;



    //***********************Colour Values for Start Photo *************************************
    int redValueStart = 0;
    int greenValueStart = 0;
    int blueValueStart = 0;
    //********************* Colour Values for End Photo ****************************************
    int redValueEnd = 0;
    int greenValueEnd = 0;
    int blueValueEnd = 0;
    //**********************Colour Values for intermediate photo********************************
    int redValue = 0;
    int greenValue = 0;
    int blueValue = 0;
    //////////////////////////////////////////////////////////////////////////////////////////////////


    for(int i = 0; i < pixelArrayStart.length; i++)//loops colums
    {

    //Gets the pixel and the color of that pixel
    pixelObjStart = pixelArrayStart[i];
    redValueStart = pixelObjStart.getRed();
    greenValueStart = pixelObjStart.getGreen();
    blueValueStart = pixelObjStart.getBlue();
    pixelObjEnd = pixelArrayEnd[i];
    redValueEnd = pixelObjEnd.getRed();
    greenValueEnd = pixelObjEnd.getGreen();
    blueValueEnd = pixelObjEnd.getBlue();




    redValue = redValueStart +((redValueEnd - redValueStart)/(numStages + 1))*k;
    greenValue = greenValueStart +((greenValueEnd - greenValueStart)/(numStages + 1))*k;
    blueValue = blueValueStart +((blueValueEnd - blueValueStart)/(numStages + 1))*k;

    pixelObjStart.setRed(redValue);
    pixelObjStart.setGreen(greenValue);
    pixelObjStart.setBlue(blueValue);






    }

    }






    }// end of class Picture, put all new methods before this

  4. #4
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default

    There may be some sort of algorithm at play within those
    for-loops, but even so, just because it has a method called
    morphStage(Picture, Picture, int, int), this doesn't make
    it so.

    Maybe this code is total junk, after all, you posted it
    with the statement that this is the code you are
    frusturated with. If you believe the problem is in this
    code, can you be more specific?

    I'm guessing you've been given this code and have been
    told it is complete and functioning (I'm being an optomist).
    I'm guessing that you are having difficulty rendering the
    final output.

    But this is all guessing on my part.
    You need to come up with one distinct question that clearly
    states the problem you are having.

    The only reason I am responding to this post is that I
    found the topic interesting, especially if the code you
    have supplied works. It might be a morph of a 2D image,
    which I would like to see.

    Anyway, be more exact.
    I don't see anything in the code you presented that is
    frustrating.


    Java Code:
    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.text.*;
    
    /**
     * A class that represents a picture. This class inherits from 
     * SimplePicture and allows the student to add functionality to
     * the Picture class. 
     * 
     * Copyright Georgia Institute of Technology 2004-2005
     * @author Barbara Ericson ericson@cc.gatech.edu
     */
    
    public class Picture3darraay extends SimplePicture{
    
      public Picture3darraay(){
        super(); 
      }
    
      public Picture3darraay(String fileName){
        super(fileName);
      }
    
      /**
       * Constructor that takes the width and height
       * @param width the width of the desired picture
       * @param height the height of the desired picture
       */
    
      public Picture3darraay(int width, int height){
        super(width,height);
      }
    
      /**
       * Constructor that takes a picture and creates a 
       * copy of that picture
       */
      public Picture3darraay(Picture copyPicture){
        super(copyPicture);
      }
    
      ////////////////////// methods ///////
      public String toString(){
        String output = "Picture, filename " + getFileName() + 
                        " height " + getHeight() 
                        + " width " + getWidth();
        return output;
      }
    
      //MorphStage method
      public void morphStage(Picture startPicture,
                             Picture endPicture,
                             int numStages, int k){
        Pixel[] pixelArrayStart = startPicture.getPixels(); 
        Pixel[] pixelArrayEnd   = endPicture.getPixels();
        Pixel pixelObjEnd   = null;
        Pixel pixelObjStart = null;
    
        //***************** Colour Values for Start Photo *****
        int redValueStart   = 0;
        int greenValueStart = 0;
        int blueValueStart  = 0;
        //***************** Colour Values for End Photo *******
        int redValueEnd   = 0;
        int greenValueEnd = 0;
        int blueValueEnd  = 0;
        //***************** Colour Values for intermediate photo***
        int redValue   = 0;
        int greenValue = 0;
        int blueValue  = 0;
    
        for(int i = 0; i < pixelArrayStart.length; i++){
    
          //Gets the pixel and the color of that pixel
          pixelObjStart   = pixelArrayStart[i];
          redValueStart   = pixelObjStart.getRed();
          greenValueStart = pixelObjStart.getGreen();
          blueValueStart  = pixelObjStart.getBlue();
          pixelObjEnd     = pixelArrayEnd[i];
          redValueEnd     = pixelObjEnd.getRed();
          greenValueEnd   = pixelObjEnd.getGreen();
          blueValueEnd    = pixelObjEnd.getBlue();
    
          redValue   = redValueStart +((redValueEnd - redValueStart)/
                                       (numStages + 1))*k; 
          greenValue = greenValueStart +((greenValueEnd - greenValueStart)/
                                       (numStages + 1))*k; 
          blueValue  = blueValueStart +((blueValueEnd - blueValueStart)/
                                       (numStages + 1))*k; 
    
          pixelObjStart.setRed(redValue);
          pixelObjStart.setGreen(greenValue);
          pixelObjStart.setBlue(blueValue);
        }
      }
    }

  5. #5
    Mabyboi is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    Im using this to morph pictures in dr.Java, but the issue im having is that all the pictures are coming up white....

  6. #6
    CurtisLemon is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Default

    Highlighted the problem areas where I made changes.


    public void morphStage(Picture startPicture, Picture endPicture, int numStages, int k)
    {
    Pixel[] pixelArrayStart = startPicture.getPixels();
    Pixel[] pixelArrayEnd = endPicture.getPixels();
    Pixel[][][] pixelRGB = null;
    Pixel pixelObjEnd = null;
    Pixel pixelObjStart = null;
    Pixel pixelObjNew = null;


    //***********************Colour Values for Start Photo *************************************
    int redValueStart = 0;
    int greenValueStart = 0;
    int blueValueStart = 0;
    //********************* Colour Values for End Photo ****************************************
    int redValueEnd = 0;
    int greenValueEnd = 0;
    int blueValueEnd = 0;
    //**********************Colour Values for intermediate photo********************************
    int redValue = 0;
    int greenValue = 0;
    int blueValue = 0;
    //////////////////////////////////////////////////////////////////////////////////////////////////


    for(int y = 0; y < getHeight(); )//loops colums
    {
    for(int x =0; x < getWidth(); )//loops rows
    {
    //Gets the pixel and the color of that pixel
    pixelObjStart = this.getPixel(x,y);
    redValueStart = pixelObjStart.getRed();
    greenValueStart = pixelObjStart.getGreen();
    blueValueStart = pixelObjStart.getBlue();
    pixelObjEnd = this.getPixel(x,y);
    redValueEnd = pixelObjEnd.getRed();
    greenValueEnd = pixelObjEnd.getGreen();
    blueValueEnd = pixelObjEnd.getBlue();


    for(int i = 0; i < pixelArrayStart.length; )//Morhphing loop
    {
    pixelObjStart = pixelArrayStart[i];
    redValue = redValueStart +((redValueEnd - redValueStart)/(numStages + 1))*k;
    greenValue = greenValueStart +((greenValueEnd - greenValueStart)/(numStages + 1))*k;
    blueValue = blueValueStart +((blueValueEnd - blueValueStart)/(numStages + 1))*k;

    pixelObjNew.setRed(redValue);
    pixelObjNew.setGreen(greenValue);
    pixelObjNew.setBlue(blueValue);



    x++;
    y++;
    i++;
    }
    }
    }
    }

  7. #7
    Peltoltura is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: How to make a morph Method

    does anyone know if this actually works? , i need the method to have more than one stage in between the start and end picture...

Similar Threads

  1. creating a make grid method
    By Matt198525 in forum New To Java
    Replies: 13
    Last Post: 10-29-2010, 02:47 AM
  2. Replies: 6
    Last Post: 12-13-2009, 02:44 AM
  3. Static method cannot make new objects?
    By zerkz in forum New To Java
    Replies: 2
    Last Post: 10-15-2009, 03:17 AM
  4. Use an internal Method or Make a class file?
    By TimHuey in forum New To Java
    Replies: 2
    Last Post: 09-18-2009, 03:06 PM
  5. Morph Cone to Cylinder!
    By aRTx in forum Advanced Java
    Replies: 2
    Last Post: 05-09-2009, 05:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •