Skip to Content Java Solaris Communities Sun Store Join SDN My Profile Why Join?

Developer Forums
Java Technology Forums - canny algorithm for edge detection
Java Forums
 
Search Forums
 
 
Back to Forum   Feedback About Forums Topics: « Previous | Next
This topic has 129 replies on 9 pages.    « Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Next »
Shubhadip_Ray
Posts:1
Registered: 11/16/04
Re: canny algorithm for edge detection   
Nov 16, 2004 3:46 AM (reply 45 of 129)

 
Dear Sir,
I am implementing the Canny edge-detector algorithm. You wrote that you would be posting it somewhere. Could you give me the link to the posting or else can you mail the implementation to shubhadipray@yahoo.com (my mail-id)?
Thank you,

Shubhadip Ray
 
micciP
Posts:1
Registered: 12/2/04
Re: canny algorithm for edge detection   
Dec 2, 2004 3:20 AM (reply 46 of 129)

 
hi,

im a thrid uear uni student in london and i am doing a project on finger print analysis. i was wonder *** if i could have a copy of the canny algorithm becoz im going to be using edge extraction to create the images required for the print matching.

thanks

mandi
 
Charlize
Posts:11
Registered: 8/30/04
Re: canny algorithm for edge detection   
Dec 2, 2004 3:29 AM (reply 47 of 129)

 
if you can post your email address, i will send you the code. i'm not the author of the code but the author (Leandro) said whoever has the code can pass it on to others. I'm telling you this so that you can give Leandro the credit for the code and acknowledge his work.
 
stevedaskam
Posts:18
Registered: 2/18/00
Re: canny algorithm for edge detection   
Dec 3, 2004 6:48 AM (reply 48 of 129)

 
Hi,

Can you please send me a copy of the algorithm also. My email address is steve<at>Daskam.com.

Thanks,
Steve
 
trupz27
Posts:25
Registered: 12/3/04
Re: canny algorithm for edge detection   
Dec 3, 2004 7:32 AM (reply 49 of 129)

 
hello
i am interested in getting the code for edge dection
i am doing this project for pattern recognition using java
pls send as soon as possible

i am as student ans have a project deadline
thanx
 
Charlize
Posts:11
Registered: 8/30/04
Re: canny algorithm for edge detection   
Dec 3, 2004 7:34 AM (reply 50 of 129)

 
you need to post your email address
 
trupz27
Posts:25
Registered: 12/3/04
Re: canny algorithm for edge detection   
Dec 3, 2004 7:39 AM (reply 51 of 129)

 
hey
where didi you post it
pls do send me a copy
my email address trupz27@gmail.com

thanx (hurry)
trupz
 
trupz27
Posts:25
Registered: 12/3/04
Re: canny algorithm for edge detection   
Dec 3, 2004 8:30 AM (reply 52 of 129)

 
hey thanx
received ur files
gr8 help

thanx a ton
:-))
 
sleepPig83
Posts:1
Registered: 12/7/04
Re: canny algorithm for edge detection   
Dec 7, 2004 7:45 AM (reply 53 of 129)

 
Hello, may i have a copy of the canny algorithm source code? I need it for my project also. Can u post the source code to my email account?
 
ricyvivek
Posts:2
Registered: 12/7/04
Re: canny algorithm for edge detection   
Dec 7, 2004 7:53 AM (reply 54 of 129)

 
hi!

hav u still got canny edge detecting algorighm. if u hav then plz send it to me on ricyvivek@yahoo.com

and i wanted to ask u one more thing that sobel is easy and simple algorithm but canny is better. what do u say?
 
ricyvivek
Posts:2
Registered: 12/7/04
Re: canny algorithm for edge detection   
Dec 7, 2004 7:57 AM (reply 55 of 129)

 
hi!

i read that u hav got canny edge detection programm. can u plz send it to me.
i am in a same situation as u were before some time. i am a student and i have a project dead line.

plz send it to me...
thanx
 
robyn113
Posts:2
Registered: 12/8/04
Re: canny algorithm for edge detection   
Dec 8, 2004 9:31 AM (reply 56 of 129)

 
Hello,
I am a student of electronic engineering of Salerno university (ITALY). I am developing a thesis on the MAM systems and I would be interested to give the source code of canny algorithm for edge detection.
Hoping to receive soon your news, I offer you my more kindest regards.
 
robyn113
Posts:2
Registered: 12/8/04
Re: canny algorithm for edge detection   
Dec 8, 2004 9:33 AM (reply 57 of 129)

 
Hello,
I am a student of electronic engineering of Salerno university (ITALY). I am developing a thesis on the MAM systems and I would be interested to give the source code of canny algorithm for edge detection.
Hoping to receive soon your news, I offer you my more kindest regards.
 
jboeing
Posts:929
Registered: 9/30/02
Re: canny algorithm for edge detection   
Dec 8, 2004 1:15 PM (reply 58 of 129)

 
With all these requests for the code, maybe you should as permission from Leandro to simply post it here. Then, you won't have to bother with all these email requests. Just a thought.
 
leandrotrevisan
Posts:107
Registered: 11/12/03
Re: canny algorithm for edge detection   
Dec 9, 2004 4:12 AM (reply 59 of 129)

 
wow,
this topic never dies!
50+ replies!

Charlize told me there are lot of people posting requests here...
So, as jboeing suggest, I'm posting the code here

package tools;
 
import java.awt.*;
import java.awt.image.*;
 
public class EdgeDetector extends Component {
 
	public EdgeDetector() {
		threshold1 = 50;
		threshold2 = 230;
		setThreshold(128);
		setWidGaussianKernel(15);
	}
 
	public void process() throws EdgeDetectorException {
		if (threshold < 0 || threshold > 255)
			throw new EdgeDetectorException("The value of the threshold is out of its valid range.");
		if (widGaussianKernel < 3 || widGaussianKernel > 40)
			throw new EdgeDetectorException("The value of the widGaussianKernel is out of its valid range.");
		width = sourceImage.getWidth(this);
		height = sourceImage.getHeight(this);
		picsize = width * height;
		data = new int[picsize];
		magnitude = new int[picsize];
		orientation = new int[picsize];
		float f = 1.0F;
		canny_core(f, widGaussianKernel);
		thresholding_tracker(threshold1, threshold2);
		for (int i = 0; i < picsize; i++)
			if (data[i] > threshold)
				data[i] = 0xff000000;
			else
				data[i] = -1;
 
		edgeImage = pixels2image(data);
		data = null;
		magnitude = null;
		orientation = null;
	}
 
	private void canny_core(float f, int i) {
		boolean flag = false;
		boolean flag1 = false;
		derivative_mag = new int[picsize];
		float af4[] = new float[i];
		float af5[] = new float[i];
		float af6[] = new float[i];
		data = image2pixels(sourceImage);
		int k4 = 0;
		do {
			if (k4 >= i)
				break;
			float f1 = gaussian(k4, f);
			if (f1 <= 0.005F && k4 >= 2)
				break;
			float f2 = gaussian((float) k4 - 0.5F, f);
			float f3 = gaussian((float) k4 + 0.5F, f);
			float f4 = gaussian(k4, f * 0.5F);
			af4[k4] = (f1 + f2 + f3) / 3F / (6.283185F * f * f);
			af5[k4] = f3 - f2;
			af6[k4] = 1.6F * f4 - f1;
			k4++;
		} while (true);
		int j = k4;
		float af[] = new float[picsize];
		float af1[] = new float[picsize];
		int j1 = width - (j - 1);
		int l = width * (j - 1);
		int i1 = width * (height - (j - 1));
		for (int l4 = j - 1; l4 < j1; l4++) {
			for (int l5 = l; l5 < i1; l5 += width) {
				int k1 = l4 + l5;
				float f8 = (float) data[k1] * af4[0];
				float f10 = f8;
				int l6 = 1;
				int k7 = k1 - width;
				for (int i8 = k1 + width; l6 < j; i8 += width) {
					f8 += af4[l6] * (float) (data[k7] + data[i8]);
					f10 += af4[l6] * (float) (data[k1 - l6] + data[k1 + l6]);
					l6++;
					k7 -= width;
				}
 
				af[k1] = f8;
				af1[k1] = f10;
			}
 
		}
 
		float af2[] = new float[picsize];
		for (int i5 = j - 1; i5 < j1; i5++) {
			for (int i6 = l; i6 < i1; i6 += width) {
				float f9 = 0.0F;
				int l1 = i5 + i6;
				for (int i7 = 1; i7 < j; i7++)
					f9 += af5[i7] * (af[l1 - i7] - af[l1 + i7]);
 
				af2[l1] = f9;
			}
 
		}
 
		af = null;
		float af3[] = new float[picsize];
		for (int j5 = k4; j5 < width - k4; j5++) {
			for (int j6 = l; j6 < i1; j6 += width) {
				float f11 = 0.0F;
				int i2 = j5 + j6;
				int j7 = 1;
				for (int l7 = width; j7 < j; l7 += width) {
					f11 += af5[j7] * (af1[i2 - l7] - af1[i2 + l7]);
					j7++;
				}
 
				af3[i2] = f11;
			}
 
		}
 
		af1 = null;
		j1 = width - j;
		l = width * j;
		i1 = width * (height - j);
		for (int k5 = j; k5 < j1; k5++) {
			for (int k6 = l; k6 < i1; k6 += width) {
				int j2 = k5 + k6;
				int k2 = j2 - width;
				int l2 = j2 + width;
				int i3 = j2 - 1;
				int j3 = j2 + 1;
				int k3 = k2 - 1;
				int l3 = k2 + 1;
				int i4 = l2 - 1;
				int j4 = l2 + 1;
				float f6 = af2[j2];
				float f7 = af3[j2];
				float f12 = hypotenuse(f6, f7);
				int k = (int) ((double) f12 * 20D);
				derivative_mag[j2] = k >= 256 ? 255 : k;
				float f13 = hypotenuse(af2[k2], af3[k2]);
				float f14 = hypotenuse(af2[l2], af3[l2]);
				float f15 = hypotenuse(af2[i3], af3[i3]);
				float f16 = hypotenuse(af2[j3], af3[j3]);
				float f18 = hypotenuse(af2[l3], af3[l3]);
				float f20 = hypotenuse(af2[j4], af3[j4]);
				float f19 = hypotenuse(af2[i4], af3[i4]);
				float f17 = hypotenuse(af2[k3], af3[k3]);
				float f5;
				if (f6 * f7 <= (float) 0
					? Math.abs(f6) >= Math.abs(f7)
					? (f5 = Math.abs(f6 * f12))
						>= Math.abs(f7 * f18 - (f6 + f7) * f16)
					&& f5
						> Math.abs(f7 * f19 - (f6 + f7) * f15) : (
							f5 = Math.abs(f7 * f12))
						>= Math.abs(f6 * f18 - (f7 + f6) * f13)
					&& f5
						> Math.abs(f6 * f19 - (f7 + f6) * f14) : Math.abs(f6)
						>= Math.abs(f7)
						? (f5 = Math.abs(f6 * f12))
							>= Math.abs(f7 * f20 + (f6 - f7) * f16)
					&& f5
						> Math.abs(f7 * f17 + (f6 - f7) * f15) : (
							f5 = Math.abs(f7 * f12))
						>= Math.abs(f6 * f20 + (f7 - f6) * f14)
					&& f5 > Math.abs(f6 * f17 + (f7 - f6) * f13)) {
					magnitude[j2] = derivative_mag[j2];
					orientation[j2] = (int) (Math.atan2(f7, f6) * (double) 40F);
				}
			}
 
		}
 
		derivative_mag = null;
		af2 = null;
		af3 = null;
	}
 
	private float hypotenuse(float f, float f1) {
		if (f == 0.0F && f1 == 0.0F)
			return 0.0F;
		else
			return (float) Math.sqrt(f * f + f1 * f1);
	}
 
	private float gaussian(float f, float f1) {
		return (float) Math.exp((-f * f) / ((float) 2 * f1 * f1));
	}
 
	private void thresholding_tracker(int i, int j) {
		for (int k = 0; k < picsize; k++)
			data[k] = 0;
 
		for (int l = 0; l < width; l++) {
			for (int i1 = 0; i1 < height; i1++)
				if (magnitude[l + width * i1] >= i)
					follow(l, i1, j);
 
		}
 
	}
 
	private boolean follow(int i, int j, int k) {
		int j1 = i + 1;
		int k1 = i - 1;
		int l1 = j + 1;
		int i2 = j - 1;
		int j2 = i + j * width;
		if (l1 >= height)
			l1 = height - 1;
		if (i2 < 0)
			i2 = 0;
		if (j1 >= width)
			j1 = width - 1;
		if (k1 < 0)
			k1 = 0;
		if (data[j2] == 0) {
			data[j2] = magnitude[j2];
			boolean flag = false;
			int l = k1;
			do {
				if (l > j1)
					break;
				int i1 = i2;
				do {
					if (i1 > l1)
						break;
					int k2 = l + i1 * width;
					if ((i1 != j || l != i)
						&& magnitude[k2] >= k
						&& follow(l, i1, k)) {
						flag = true;
						break;
					}
					i1++;
				} while (true);
				if (!flag)
					break;
				l++;
			}
			while (true);
			return true;
		} else {
			return false;
		}
	}
 
	private Image pixels2image(int ai[]) {
		MemoryImageSource memoryimagesource =
			new MemoryImageSource(
				width,
				height,
				ColorModel.getRGBdefault(),
				ai,
				0,
				width);
		return Toolkit.getDefaultToolkit().createImage(memoryimagesource);
	}
 
	private int[] image2pixels(Image image) {
		int ai[] = new int[picsize];
		PixelGrabber pixelgrabber =
			new PixelGrabber(image, 0, 0, width, height, ai, 0, width);
		try {
			pixelgrabber.grabPixels();
		} catch (InterruptedException interruptedexception) {
			interruptedexception.printStackTrace();
		}
		boolean flag = false;
		int k1 = 0;
		do {
			if (k1 >= 16)
				break;
			int i = (ai[k1] & 0xff0000) >> 16;
			int k = (ai[k1] & 0xff00) >> 8;
			int i1 = ai[k1] & 0xff;
			if (i != k || k != i1) {
				flag = true;
				break;
			}
			k1++;
		} while (true);
		if (flag) {
			for (int l1 = 0; l1 < picsize; l1++) {
				int j = (ai[l1] & 0xff0000) >> 16;
				int l = (ai[l1] & 0xff00) >> 8;
				int j1 = ai[l1] & 0xff;
				ai[l1] =
					(int) (0.29799999999999999D * (double) j
						+ 0.58599999999999997D * (double) l
						+ 0.113D * (double) j1);
			}
 
		} else {
			for (int i2 = 0; i2 < picsize; i2++)
				ai[i2] = ai[i2] & 0xff;
 
		}
		return ai;
	}
 
	public void setSourceImage(Image image) {
		sourceImage = image;
	}
 
	public Image getEdgeImage() {
		return edgeImage;
	}
 
	public void setThreshold(int i) {
		threshold = i;
	}
 
	public void setWidGaussianKernel(int i) {
		widGaussianKernel = i;
	}
 
	final float ORIENT_SCALE = 40F;
	private int height;
	private int width;
	private int picsize;
	private int data[];
	private int derivative_mag[];
	private int magnitude[];
	private int orientation[];
	private Image sourceImage;
	private Image edgeImage;
	private int threshold1;
	private int threshold2;
	private int threshold;
	private int widGaussianKernel;
}
 
//second file
 
package tools;
 
public class EdgeDetectorException extends Exception
{
  public EdgeDetectorException()
  {
    //do something?
  }
  public EdgeDetectorException(String s)
  {
    super(s);
  }
}
 
 
Click to email this message Email this Topic

Edit this Topic
Powered by Jive Forums