Results 1 to 7 of 7
Thread: How to make a morph Method
- 11-15-2010, 03:51 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
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.
- 11-15-2010, 06:57 AM #2
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
- 11-15-2010, 07:05 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
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
- 11-15-2010, 04:53 PM #4
Senior Member
- Join Date
- Jul 2008
- Posts
- 125
- Rep Power
- 0
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); } } }
- 11-15-2010, 07:24 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
Im using this to morph pictures in dr.Java, but the issue im having is that all the pictures are coming up white....
- 11-15-2010, 09:04 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 1
- Rep Power
- 0
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++;
}
}
}
}
- 11-15-2011, 11:41 PM #7
Member
- Join Date
- Nov 2011
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
creating a make grid method
By Matt198525 in forum New To JavaReplies: 13Last Post: 10-29-2010, 02:47 AM -
How to make a MouseListener Method to do multy tasks?
By Laythe in forum Java AppletsReplies: 6Last Post: 12-13-2009, 02:44 AM -
Static method cannot make new objects?
By zerkz in forum New To JavaReplies: 2Last Post: 10-15-2009, 03:17 AM -
Use an internal Method or Make a class file?
By TimHuey in forum New To JavaReplies: 2Last Post: 09-18-2009, 03:06 PM -
Morph Cone to Cylinder!
By aRTx in forum Advanced JavaReplies: 2Last Post: 05-09-2009, 05:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks