Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Chain Code (Freeman)

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Chain Code (Freeman)

    hallo, i have to do programming on freeman chain code to traces the pixels of signatures. I usd bitmap image which in black and white. Can someone help me on how to do it in java?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Chain Code (Freeman)

    What have you tried? Where are you stuck?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chain Code (Freeman)

    i didn't try anything yet, because i not have any idea about chain code in java. i need someone to give me idea on doing this.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Chain Code (Freeman)

    Describe the algorithm that you are trying to code in more specific terms.
    To get at the pixels in an image there is the getPixel methods for example.

  5. #5
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,234
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Chain Code (Freeman)

    i didn't try anything yet, because i not have any idea about chain code in java. i need someone to give me idea on doing this.
    You mean you didn't even try a web search? We have no clue where you are stuck - the algorithm, reading images, java in general...the question is vague enough to have so many different answers you are not helping yourself receive the help you wish.

  6. #6
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chain Code (Freeman)

    okay. it is like this.

    i have a signature that i get from a tablet, then i need to trace all the pixels of the signature using the chain code algorithm. the chain have 8 connection, which is from number 0-7. and i need to get the code which can trace pixels that have junctions.

    i have found some codes from internet. but more in matlab, or in C/c#, so i need help, on how doing it in java.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Chain Code (Freeman)

    If you have an image in a BufferedImage object you can look at its pixels by using the getRGB method.

    None of the terms you are using (signature, tablet, chain code, 8 connection, junctions) to describe your problem relate to java programming. If you have a design or algorithm that you need help with you will have to post the steps in it that you need help with to write the program in the java language.

  8. #8
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chain Code (Freeman)

    i have run this program,

    import javax.imageio.ImageIO;
    import java.io.*;
    import java.io.IOException;
    import java.awt.image.BufferedImage;
    import java.util.Vector;
     
    public class Imagersteg {
     
     
        static Vector<Integer> checkx = new Vector<Integer>();
        static Vector<Integer> checky = new Vector<Integer>();
        static Vector<Integer> direct = new Vector<Integer>();
     
      public static void main( String[] args ) throws IOException{
     
        BufferedImage image = null;
     
        File imagefile = new File("C\\Users\\INTAN\\sign.bmp");
        image = ImageIO.read(imagefile);
     
        int w=image.getWidth();
        int h=image.getHeight();
     
        int x, y;
        x = y = 0;
     
        boolean flag = false;
        for(int k=0;k<h;k++)
        {
          for(int j=0;j<w;j++)
          {
            int rgbValue= image.getRGB( j, k) + 0xFFFFFF + 1;
     
            if(rgbValue == 0)
            {
              x = j;
              y = k;
     
              flag = true;
     
              break;
            }
          }
     
          if(flag)
            break;
        }
     
        System.out.println("Success");
        System.out.println( x + " " + y);
     
        int[] lx = new int[8];
        int[] ly = new int[8];
        lx[0] = 0;
        lx[1] = 1;
        lx[2] = 1;
        lx[3] = 1;
        lx[4] = 0;
        lx[5] = -1;
        lx[6] = -1;
        lx[7] = -1;
        ly[0] = -1;
        ly[1] = -1;
        ly[2] = 0;
        ly[3] = 1;
        ly[4] = 1;
        ly[5] = 1;
        ly[6] = 0;
        ly[7] = -1;
        int l = 0;
        int a = 0;
        int b = 0;
        int beforex = 0;
        int beforey = 0;
     
     
        boolean flagz = false;
        for(int j = 0; j < 500; j++)
        {
          if(flagz)
            break;
          for (int i = 0; i < 8; i++)
          {
        	if(check(x + lx[i],y + ly[i]) && !((x + lx[i] == beforex) && (y + ly[i] == beforey)))
            //if(!((x + lx[i] == beforex) && (y + ly[i] == beforey)))
            {	
              if((image.getRGB(x + lx[i], y + ly[i])  == -16777216))
              {
                l = i;
     
                a = x + lx[i];
                b = y + ly[i];
     
                checkx.add(x);
                checky.add(y);
                beforex = x;
                beforey = y;
     
                x = a;
                y = b;
     
                break;
              }
              checkx.add(x);
              checky.add(y);
            }
     
            if(i == 7)
              flagz = true;
          }
     
          System.out.println(x + " " + y + " = " + l);
          direct.add(l);
     
        }
     
     
        Integer[] chain= new Integer[direct.size()];
    	direct.copyInto(chain);
    	for(int i = 0; i < chain.length; i++)
    	{
    		System.out.println( "chaincode = " + chain[i]);
    	}
     
    	int count = 0;
     
    	for(int i = 0; (i + 2) < chain.length; i= i+2)  //direction in array
    	{
    		for(int j = 0; j < 8; j++)  //direction 0 to 7
    		{
    			if(chain[i] == j)  //if 2nd pixel = i 
    			{
    				if(chain[i+1] == j+1 || chain[i+1] == j-1) //if (3rd pixel = i+1) || (3rd pixel = i-1)
    				{
    					count++;
    				}
    			}
    		}
    	}
    	System.out.println("total input =" + count);
     
      }
     
    public static boolean check(int x, int y){
     
     
    	Integer[] xed= new Integer[checkx.size()];
    	Integer[] yed= new Integer[checky.size()];
    	checkx.copyInto(xed);
    	checky.copyInto(yed);
    	for( int i = 0; i < xed.length; i++)
    	{
    		//System.out.println(x + " . " + xed[i] + " . "  + y + " . "  + yed[i]);
    		if((x == xed[i]) && (y == yed[i])){
    			//System.out.println(x + " . " + xed[i] + " . "  + y + " . "  + yed[i]);
    			return false;
    		}
    	}
    	return true;
     
     
    }
    }


    But i have got error, why?blabla.jpg
    Last edited by aelynne; February 23rd, 2012 at 02:45 PM.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Chain Code (Freeman)

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

    The program can not find the file. Make sure the file is located where the program is looking for it.

    Please post text instead of an image. It is not possible to copy and paste from an image.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  10. #10
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chain Code (Freeman)

    its okay, i have successed. but, this program only for straightforward signature, doesn't have any junction. If the signature is complex with junction, how to do that?

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Chain Code (Freeman)

    Can you ask your questions in java programming terms?
    The words you are using have no meaning when talking about a java program: signature and junction.
    These words relate to your problem, not how to code a program.

  12. #12
    Junior Member
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Chain Code (Freeman)

    i have a chain code coding for straight-forward signature,and now i need to do for the signature that have intersection, how?

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Chain Code (Freeman)

    Can you ask your questions in java programming terms?
    The words you are using have no meaning when talking about a java program: signature, chain code and intersection
    These words relate to your problem, not how to code a program.

  14. #14
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Chain Code (Freeman)

    Quote Originally Posted by fzdabc View Post
    hello,have you finished this project now? Can you show me your source code ? I also got stuck in this problem these days.
    That isn't how this works. You're essentially saying, "You finished your homework, and I haven't, so can I see yours?". Make your own attempt, then post a specific question along with an SSCCE if you get stuck.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. code to refresh and check the code of a webpage..
    By vaggelis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2012, 06:43 AM
  2. Help merging program code with GUI code
    By Wilha in forum AWT / Java Swing
    Replies: 2
    Last Post: January 25th, 2012, 06:03 PM
  3. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 07:36 AM
  4. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 08:30 PM
  5. How to represent a chain of moves?
    By maikeru in forum Collections and Generics
    Replies: 0
    Last Post: December 31st, 2009, 12:24 AM