Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to assess similarity of images. #11

Closed
emiln opened this issue Aug 31, 2015 · 1 comment · Fixed by #16
Closed

Ability to assess similarity of images. #11

emiln opened this issue Aug 31, 2015 · 1 comment · Fixed by #16

Comments

@emiln
Copy link
Owner

emiln commented Aug 31, 2015

It would be great to be able to express flows like: If this region of the screen is similar to this old version of it, perform some command. One measure for similarity could be simple color histograms. Here's my thought on a first version:

Similarity is calculated by:

  • Creating 8 buckets for each of red, green, and blue. The first is for values [0 31], the next [32 63] etc.
  • For each pixel considered, increment the proper bucket for its red, green, and blue color value.
  • Normalize all buckets relative to the number of pixels considered.
  • Calculate the absolute differences in normalized buckets values between the two images.
  • Sum up the differences.

Note that this means you can save a "fingerprint" of an image by saving its bucket values.

@emiln
Copy link
Owner Author

emiln commented Aug 31, 2015

The Robot class has a nice method for getting a portion of the screen, which should work well for getting test data. Having a buffered image, you can do something along the lines of:

(let [dummy (int-array 3)]
  (for [x (range (.getWidth img))
        y (range (.getHeight img))]
    (-> img (.getData) (.getPixel x y dummy))))

to get all the pixels, which are really int arrays with three elements: red, green, and blue.

emiln pushed a commit that referenced this issue Sep 1, 2015
It is now possible to compute a simple color histogram of a given
BufferedImage. The histogram uses 8 buckets for each color, and each
bucket contains a normalized number between 0 and 255. The 8 buckets
sum up to 255. Why 255? It will make it really easy to create reader
tags with hexadecimal literals later on, which can be entered in the
EDN files without too much verbosity. I envision a reader tag like

`#cljck.color.Histogram[0x0011223344556677 0x8899aabbccddeeff
                        0x0123456789abcdef]`

which is a fairly compact notation for a histogram.
emiln added a commit that referenced this issue Sep 1, 2015
There is now a function to compare two histograms and return their
difference between 0 (very similar) and 1 (very different).
@emiln emiln mentioned this issue Sep 2, 2015
emiln pushed a commit that referenced this issue Sep 2, 2015
@emiln emiln closed this as completed in #16 Sep 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant