Author Topic: Java pixel comparison possible?  (Read 1945 times)

0 Members and 1 Guest are viewing this topic.

Offline DreX

  • Serf
  • *
  • Posts: 42
  • Cookies: -5
    • View Profile
Java pixel comparison possible?
« on: September 12, 2014, 01:57:33 am »
Can I create the following program in Java:
(this is a very crude plan):
I need to be able to compare two images. All pictures will be screenshoots (so the resolution will/ should be the same for every image). First I will make "reference images" for (0-9). Then I take another sc and and "disect" the image to be in one-digit numbers (0-9). I will then compare them and find out the number that is in picture.

I was thinking along the lines: import image. Compare every pixel with the same pixel from "reference" picture. If the pictures are equal return true. If true then int x="referencal" image number.

If this is possible I only wish to know in what chapter I need to look (ArrayList, Classes, Swing......).

Offline Matriplex

  • Knight
  • **
  • Posts: 323
  • Cookies: 66
  • Java
    • View Profile
Re: Java pixel comparison possible?
« Reply #1 on: September 12, 2014, 04:09:51 am »
You can do this using artificial neural networks. Look up heaton introduction to hopfield networks in java. It's a good book for beginners. Or you could extract the binary image data as a string and compare the two. This would be super easy, but the other image would have to be exactly the same.
« Last Edit: September 12, 2014, 04:10:46 am by Matriplex »
\x64\x6F\x75\x65\x76\x65\x6E\x00

Offline DreX

  • Serf
  • *
  • Posts: 42
  • Cookies: -5
    • View Profile
Re: Java pixel comparison possible?
« Reply #2 on: September 12, 2014, 09:41:15 am »
You can do this using artificial neural networks. Look up heaton introduction to hopfield networks in java. It's a good book for beginners. Or you could extract the binary image data as a string and compare the two. This would be super easy, but the other image would have to be exactly the same.

Thanks. Gonna look into binary image first.

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Java pixel comparison possible?
« Reply #3 on: September 12, 2014, 02:01:35 pm »
Here is a small example that I made for one of the weekly challenges here. It shows the very basics for reading an image and accessing and comparing single pixels. The task was to find the one pixel that is different from the others (with me making the assumption that it is not the first one).

Code: (Java) [Select]
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class DirtyPixel {

    public static void main(String[] args) throws IOException {
        BufferedImage image = ImageIO.read(new File("chalx.png"));
        int defRgb = image.getRGB(0, 0);
        for (int x = 0; x < image.getWidth(); x++) {
            for (int y = 0; y < image.getHeight(); y++) {
                int rgb = image.getRGB(x, y);
                if(defRgb != rgb){
                    System.out.println("x: " + x);
                    System.out.println("y: " + y);
                    break;
                }
            }
        }
    }
}

If you decide to look into ANN, you may read this:
https://evilzone.org/tutorials/artificial-neural-networks-the-basics/msg9782/#msg9782
« Last Edit: September 12, 2014, 02:03:46 pm by Deque »

Offline DreX

  • Serf
  • *
  • Posts: 42
  • Cookies: -5
    • View Profile
Re: Java pixel comparison possible?
« Reply #4 on: September 13, 2014, 11:35:54 pm »
Here is a small example that I made for one of the weekly challenges here. It shows the very basics for reading an image and accessing and comparing single pixels. The task was to find the one pixel that is different from the others (with me making the assumption that it is not the first one).

Code: (Java) [Select]
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class DirtyPixel {

    public static void main(String[] args) throws IOException {
        BufferedImage image = ImageIO.read(new File("chalx.png"));
        int defRgb = image.getRGB(0, 0);
        for (int x = 0; x < image.getWidth(); x++) {
            for (int y = 0; y < image.getHeight(); y++) {
                int rgb = image.getRGB(x, y);
                if(defRgb != rgb){
                    System.out.println("x: " + x);
                    System.out.println("y: " + y);
                    break;
                }
            }
        }
    }
}

If you decide to look into ANN, you may read this:
https://evilzone.org/tutorials/artificial-neural-networks-the-basics/msg9782/#msg9782



This will do quite nicely.
Thank you very much ^^

Offline chapp

  • Peasant
  • *
  • Posts: 87
  • Cookies: 2
    • View Profile
Re: Java pixel comparison possible?
« Reply #5 on: September 17, 2014, 10:58:16 am »
This is a task that is easily parallelised without much overhead if you want to look into that.