i m having trouble in constructing a edge detector by using the sobel kernels and expected results are the vertical, horizontal and gradient edge 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 :

Code: ( java )

import java.io.*;
public class JPEG1{

          public static void main (String args[]) {

          if (args.length != 2) {

              System.out.println("Usage: java JPEGCopy <source JPEG file> " +

                         "<target JPEG file>");

              System.exit(1);

          }


          JPEGImage imageOne = new JPEGImage();

          try {

              imageOne.read(args[0]);

          } catch (Exception e) {

              /* An exception has been thrown. This is usually because the file

                 either does not exist, or is not a JPEG image */

              System.out.println("Error reading file " + args[0]);

              System.out.println(e.getMessage());

              System.exit(1);

          }

       

          /* Make a new image the same size as the one that was read in */

          JPEGImage imageTwo = new JPEGImage(imageOne.getWidth(),

                             imageOne.getHeight());

       

          /* Copy the pixel information from image that was read in to the

             new image */

          for (int x = 0; x < imageOne.getWidth(); x++) {

              for (int y = 0; y < imageOne.getHeight(); y++) {

              /* Get the values from imageOne */
 
              int red = imageOne.getRed(x,y);

              int green = imageOne.getGreen(x,y);

              int blue = imageOne.getBlue(x,y);

              /* Put these values into imageTwo */

              imageTwo.setRGB(x, y, red, green, blue);

              }

          }

       

          /* Write the new image out to a file. Again exceptions might occur */

          try {

              imageTwo.write(args[1]);

          } catch (Exception e) {

              System.out.println("Error writing file " + args[1]);

              System.out.println(e.getMessage());

              System.exit(1);

          }

       

          }

      }

Recommended Answers

All 5 Replies

What's the trouble exactly? And please paste your code within code tags.

the problem is that i cant think of how to continue using the above code, using the kernels.

I will suggest you the same as Phaelax again, try to enclose your code within code tags. Your code is not readable.
As you are saying you can't think of how to continue using the above code, is it the code provided by your prof (i will assume some skeleton code) or something you copied from somewhere?

yes, you must specify your exact problem.. i guess you are talking that you dont knw how to use this code in a software you are willing to make??

commented: Well done for providing complet working solution to given problem -2

The program is not edge detection, you are doing simple copy paste logic. for edge detection after deriving the image pixel detail apply formula for edge detection.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.