473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

This is about edge detection using java

constructing a edge detector using sobel kernels with a discrete convolution algorithm. The result should give a vertical edge image, a horizontal edge image and a gradient image.

Sobel kernels :


[-1 0 1
hx = -2 0 2 and
-1 0 1]


[-1 -2 -1
hy = 0 0 0
1 2 1]


gradeint magnitude and direction:

g = (g2x + g2y) 1/2 and (theta) = tan-1 (gy/gx)

The following code can be used :

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class JPEG1{
  4.  
  5.  
  6.     public static void main (String args[]) {
  7.     /* Check that the user has provided the right number of arguments */
  8.     if (args.length != 2) {
  9.         System.out.println("Usage: java JPEGCopy <source JPEG file> " + 
  10.                    "<target JPEG file>");
  11.         System.exit(1);
  12.     }
  13.  
  14.     /* Create an empty image. We will read an image from a file into
  15.        this object */
  16.     JPEGImage imageOne = new JPEGImage();
  17.  
  18.     /* Try to open the file. This may cause an exception if the name 
  19.        given is not a valid JPEG file so we need to catch the exceptions */
  20.     try {
  21.         imageOne.read(args[0]);
  22.     } catch (Exception e) {
  23.         /* An exception has been thrown. This is usually because the file
  24.            either does not exist, or is not a JPEG image */
  25.         System.out.println("Error reading file " + args[0]);
  26.         System.out.println(e.getMessage());
  27.         System.exit(1);
  28.     }
  29.  
  30.     /* Make a new image the same size as the one that was read in */
  31.     JPEGImage imageTwo = new JPEGImage(imageOne.getWidth(),
  32.                        imageOne.getHeight());
  33.  
  34.     /* Copy the pixel information from image that was read in to the 
  35.        new image */
  36.     for (int x = 0; x < imageOne.getWidth(); x++) {
  37.         for (int y = 0; y < imageOne.getHeight(); y++) {
  38.         /* Get the values from imageOne */
  39.         int red = imageOne.getRed(x,y);
  40.         int green = imageOne.getGreen(x,y);
  41.         int blue = imageOne.getBlue(x,y);
  42.         /* Put these values into imageTwo */
  43.         imageTwo.setRGB(x, y, red, green, blue);
  44.         }
  45.     }
  46.  
  47.     /* Write the new image out to a file. Again exceptions might occur */
  48.     try {
  49.         imageTwo.write(args[1]);
  50.     } catch (Exception e) {
  51.         System.out.println("Error writing file " + args[1]);
  52.         System.out.println(e.getMessage());
  53.         System.exit(1);
  54.     }
  55.  
  56.     }
  57. }
Feb 28 '08 #1
0 4894

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/newsgroup-faq Posting-Frequency: once a week Last-modified: 2004-07-26 Version: 2.00 URL: <http://css.nu/faq/ciwas-mFAQ.html> Maintainer: Jan Roland Eriksson...
23
by: Andrew Thompson | last post by:
This is intended to fix a long standing (cough)Java(cough) problem with which I'm sure some of you will be familiar. Sun recommends using the <OBJECT>/<EMBED> elements to cater for Java...
18
by: Mickey Segal | last post by:
On comp.lang.java.programmer we are discussing problems created for Java programs by pop-up blockers (in the thread "showDocument blocked by new microsoft pop-up blocker"). Our problem is that...
17
by: lawrence | last post by:
How is it possible that the question "How do I detect which browser the user has" is missing from this FAQ: http://www.faqts.com/knowledge_base/index.phtml/fid/125 and is only here on this...
0
by: Vincent | last post by:
Hello everybody, i'm searching a sample of c# implementation of Deriche edge detection. ( if possible, with getpixel/setpixel because i don't use pointer) i tried to adapt c or c++ code but...
3
by: jesper | last post by:
I would like some feedback on this. A while back I was trying my hand at some pathfinding for a small game I was making. I did not know anything about it so I read some stuff and came up with the...
22
by: craig | last post by:
I've declared the following as a "vector" of "lists" using STL vector< list<Edge*> > I've tried many ways to add objects to this but can't figure out how to do it. Does anyone have any tips,...
2
by: a | last post by:
where could i find an edge detection example in C#
0
by: darrenhello | last post by:
hi there, I am doing my last year's project and I have a 'little' problem. I have to do an edge detection filter. for now, some normal edge detection filters that I used worked fine but there a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.