Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Is any one who could correct my source code PLZ?(image processing

  Asked By: Sean    Date: Dec 19    Category: Java    Views: 1522
  

this code should recognize the blue point in an image. I have run
one, which alter the color of pixels and draw it again, but this one
is kidding me for 2 weeks.

Would U PLZ help me?


import java.awt.*;
import javax.swing.*;
import java.awt.image.*;

public class DefineBlue extends JApplet
{

private Image img;
public void paint(Graphics g){

super.paint(g);

MediaTracker mt=new MediaTracker(this);
img=getImage(getCodeBase(),"X.bmp");
try{
mt.waitForID(0);
}
catch(InterruptedException e)
{

}

int w=img.getWidth(this);
int h=img.getHeight(this);
int np=w*h;
int pix[]=new int[np];

PixelGrabber pg= new PixelGrabber
(img,0,0,w,h,pix,0,w);
try{
pg.getPixels();
}
catch(InterruptedException e)
{

}
g.drawString(" X",50,0);
g.drawString(" Y",100,0);
ColorModel cm= ColorModel.getRGBdefault();
for(int i=0;i<np;i++)
{
int r=cm.getRed(pix[i]);
int gr=cm.getGreen(pix[i]);
int b=cm.getBlue(pix[i]);


if((r==0) && (gr==0) && (b!=0)){

int Y=(np/w)+1;
int X=np%w;

g.drawString(""+X,50,50+20*i+10);
g.drawString(""+Y,100,50+20*i+10);
}


}

}
}

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Bernard Gutierrez     Answered On: Dec 19

1. You have not specified what is the problem with your code. I guess that it runs, but does not find the blue point.

2. I think the problem comes from the characteristic of a color  to be "blue". Let a point be colored as r = 4, gr = 5, b = 128. That point seems to be "blue". Thus, I guess the conditions on the catched r, gr, and b values should be changed. Maybe an alternative test could be, that the value of b, be much more than the values of r and gr.

 
Answer #2    Answered By: Vilhelm Fischer     Answered On: Dec 19

but error I come across, relate to line, I specify it by red font.
I have run it by "VISUAL J++" and "JDK1.4" , and the error I get is "exception in java.lang.InterruptedException is never thrown in body of corresponding try statement."

I change the code  U told me, but not here, because others could perceive what is going on.

 
Answer #3    Answered By: Kyle Fox     Answered On: Dec 19

Well, the eror seems to be purely related to java  itself. As I can guess, you may have caught an exception in the catch part of a try-catch block, but there is no function call in the try section that may cause that type of exception to be thrawn.

 




Tagged: