473,765 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

This is about edge detection using java

2 New Member
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 4922

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

Similar topics

2
2764
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 <rex@css.nu> comp.infosystems.www.authoring.stylesheets meta-FAQ v2.00 _______________________________________________________________________
23
2288
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 applets, but then uses *browser* *sniffing* Javascript to select between them. I was hoping to find/create a script that
18
2901
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 Java's showDocument method, which opens new browser windows, is blocked by some pop-up blockers. The showDocument method is blocked even if the user clicked a button in a Java program to call showDocument. As a result, a type of user-initiated...
17
2557
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 with a link to old information that suggests use of "navigator": http://developer.irt.org/script/43.htm
0
2717
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 it doesn't work if someone done it ... thanks , Vince
3
1912
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 code below. I was at the time quite satisfied with it, but reading stuff here has made me doubt it. Is this implementation valid? Is this implementation fast? The member TNode * Spread; I put it in there to
22
10783
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, or references to material that might explain it? Any help greatly appreciated.
2
5986
by: a | last post by:
where could i find an edge detection example in C#
0
1368
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 problem. I need an edge detection filter in which I can offset the edge according to a variable that the user gives. The problem is that I got no idea of how to make an edge detection filter with an offset. anyone can help please? thank you
0
9566
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9946
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.