DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Jul 2005

    help regarding image processing

    I'm doing image processing in java.In tht i want to do the glass effect.I got one calculations frm the net.It's working fine with the image of size 128X128 but i want to work for 120X160.i tried with tht calculation but it's pretty difficult for me to find exactly the flow.Here is tht code

    import java.awt.*;
    import java.applet.*;
    import java.awt.image.MemoryImageSource;
    import java.awt.image.PixelGrabber;

    public class glass extends Applet implements Runnable {

    // Only in class array.
    static public int[] PCos; // Pre-calculated Degree cos table.
    static public int[] PSin; // Pre-calculated Degree sin table.

    // private members.
    private Thread lineThread; // This thread.
    private Image img = null; // Destination image.
    private Image Original; // Original image.
    private MemoryImageSource source; // Use to convert rawbuffer to img.
    private PixelGrabber pg; // Pix grabber to access pixels.
    private int width, height; // Our dimensions.
    private int[] pixeldata; // Work buffer.
    private int[] src_data; // Original pixel buffer.
    private int[] glass_buffer; // Buffer for glass distance.
    private int[] glass_shape = {0,0,0,1,1,1,2,2,2,3,3,4,4,5,5,6,7,8,9,10,12,14,16,18,20,22,24,26,28,30};
    private int xpos,ypos,dx,dy; // Glass position, and direction.

    public void init() {
    Original = getImage (getDocumentBase(),getParameter ("image")); // Get image named 'image' in html source.
    width = getSize().width; // Get our display width.
    height= getSize().height; // Get our display height.
    pixeldata=new int [width*height]; // Work buffer is [w*h] int.
    src_data=new int [width*height]; // Source image buffer is [w*h] int.
    PSin = new int [360]; // Create 360 index array for precalc math.
    PCos = new int [360]; // Create 360 index array for precalc math.
    glass_buffer = new int [3600]; // Create glass buffer.
    setBackground (Color.black); // Turn bg to black.
    source = new MemoryImageSource(width, height, pixeldata, 0, width); // Make source = gfx from a raw buffer.
    source.setAnimated(true); // Tell it's animated :-)
    pg = new PixelGrabber(Original, 0, 0, 128, 128, src_data, 0, width); // Get pixbuffer from source image.
    try {
    } catch (InterruptedException e) {
    System.err.println("interrupted waiting for pixels!");
    img = createImage(source); // Create image from source.
    for (int i=0;i<360;i++){
    PCos [i] = (int)(256*Math.cos(Math.toRadians(i))); // Fill our pre-calc cosine table:8 bit fixed math !
    PSin [i] = (int)(256*Math.sin(Math.toRadians(i))); // Fill our pre-calc cosine table:8 bit fixed math !

    for (int i=0;i<3600;i++)
    glass_buffer [i]=255; /* Fill buffer with 0xff */

    for (int i=0;i<30;i++)
    for (int o=0;o<360;o++)
    int x1= 30 + ((i * PCos [o])>>8);
    int y1= 30 + ((i * PSin [o])>>8);
    int x2= 30 + ((glass_shape[i] * PCos [o])>>8);
    int y2= 30 + ((glass_shape[i] * PSin [o])>>8);
    glass_buffer [(y1*60)+x1]=y2*128+x2;
    xpos = 25;
    ypos = 0;
    dx = 1;
    dy = 2;
    public void start() {
    if(lineThread==null) { // Does lineThread already exists ?
    lineThread = new Thread(this); // Create new Thread.
    lineThread.setPriority(lineThread.MAX_PRIORITY); // Set highest propriety.
    lineThread.start(); // start him !

    public void stop() {
    if(lineThread!=null) { // Does lineThread already exists ?
    //lineThread.stop(); // Kill him (deprecated method)
    lineThread = null; // Dereference him.

    public void paint(Graphics g) {
    source.newPixels(0,0,width,height); // Our buffer as changed, tell it :-)
    g.drawImage(img,0,0,this); // Redraw destination image.

    public void update (Graphics g) {
    paint (g); // Call paint on Update.

    public void run() { // Thread main function.
    while(true) { // Infinite loop.
    ApplyGlass (xpos,ypos);
    xpos += dx;
    ypos += dy;
    if ((xpos>127-60) || (xpos<1)) dx *= -1; // invert x direction.
    if ((ypos>127-60) || (ypos<1)) dy *= -1; // invert y direction.
    repaint(); // Calls paint.
    try {
    lineThread.sleep(20); // Free a few cpu cycles :-).
    catch(InterruptedException e) {}

    private void ApplyGlass (int x, int y)
    int deph;
    int i,o;
    int col;
    int ptr =0;
    int source = ((y<<7)+x);

    for (i=0;i<128*128;i++) pixeldata[i]=src_data[i];
    for (i=0;i<59;i++)
    for (o=0;o<60;o++)
    deph =glass_buffer [ptr++];
    if (deph != 255)
    col = src_data [source+deph];
    pixeldata [(x+o)+((y+i)<<7)] = col;

    can anyone tell me how to change the calculation frm 128X128 to 120X160.
    I'm struggling with this code for last 2 days please help me
    thanx a lot

  2. #2
    Join Date
    Jul 2005
    SW MO, USA
    This seems to be a question about an algorithm not a Java programming problem.
    If you'll explain the algorithm that you want to implement in Java, we'll be glad to help.

  3. #3
    Join Date
    Jul 2005
    hi friend,
    i'm doing image processing in j2me.In tht i want to do a Magnifying lens effect for images.For tht i got the above mentioned calculations frm the net.It's working fine with the 128X128images.But with 120X160 r someother images it's not working fine.
    I want to draw a circle first n after selecting this Lens effect from the menu i want the Magnifying lens effect on the image for the size of the circle.The above mentioned calculation is somewhat difficult understand why this value is used here like tht.
    If u have any idea regarding this let me know
    thanx a lot n thanx for ur reply

  4. #4
    Join Date
    Jul 2005
    SW MO, USA
    Can you define the Magnifying lens effect in english?
    I see a lot of Math such as Cos and sin.
    What is the use of the value 30? int x1= 30 + ((i * PCos [o])>>8);
    Why PCos() >>8?
    Why xpos>127-60 ?

    A lot of undocumented code. Without the algorithm definition, no idea on how/why this code works or how to change it.

    Good luck.

  5. #5
    Join Date
    Jul 2005
    hi friend,
    Magnifying lens effect means Imagine if ur seeing ur hands thru a lens then how ur hands look like?I want to do tht effect in java.for tht v have select a circular portion n ve to enlarge tht portion to look like tht.For tht i got tht codings from the net only for ur convience i attachec here an image after this effect.
    thanks a lot
    Attached Images Attached Images

  6. #6
    Join Date
    Jul 2005
    SW MO, USA
    An algorithm is a list of steps to solve a problem.
    You're providing a high level description of the problem. Not a way to solve it.
    You need to apply some brain power and list the steps needed to do what you want.
    These steps will be low level and will include definitions for the questions I asked before:
    What is the use of the value 30? int x1= 30 + ((i * PCos [o])>>8);
    Why PCos() >>8?
    Why xpos>127-60 ?
    When you have the steps figured out, ask a specific question about how to do that step in Java.
    Good luck.

  7. #7
    Join Date
    Feb 2006
    hello! i would like to ask about image processing techniques using visual basic as language. i have a hard time filtering my thresholded image. there are many images caught in my cam and i want that the only two circles which serves as the marker of our object to be remained. what is the best way of solving it? i hope somebody can help me. our project checking is a stone throw away and i really nid to finish this. thank u

Similar Threads

  1. Replies: 7
    Last Post: 07-16-2013, 11:47 PM
  2. Replies: 0
    Last Post: 07-11-2005, 09:41 PM
  3. Image Problem
    By Jack in forum ASP.NET
    Replies: 2
    Last Post: 10-02-2001, 07:00 PM
  4. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM
  5. PhotoTrue: New image processing library entering public testing.
    By David Crowell in forum vb.announcements
    Replies: 0
    Last Post: 09-05-2000, 12:20 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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.