Git Product home page Git Product logo

Comments (1)

stm avatar stm commented on July 19, 2024

Symmetry and color are a bit tricky. As I understand it, your goal is to have a metric of how similar two image halves are, but only based on their color. Thus, the two images below should result in the same symmetry values.

img_redimg_blue

The following code results in horizontal symmetry values of 0.99 for both images. The steps are:

  1. first convert the RGB images into the HSV color space (hue, saturation, value)
  2. then only use the information on the hue channel (i.e., the color information)
  3. in the final step, calculate the percentage of the hue values being identical in the image halves

This approach could also be extended to incorporate e.g. the saturation into this measure (by having a weighted mean, for example).

# load image
img_red <- imagefluency::img_read("img_red.png") # change accordingly

# vertical symmetry (left vs right)
img <- OpenImageR::RGB_to_HSV(img_red)[,,1] # keep only HUE
# OpenImageR::imageShow(img)

imgW <- dim(img)[2] # image width
stimL <- img[, 1:floor(imgW / 2)] # left image half
stimR <- img[, imgW:(1 + ceiling(imgW / 2))] # right image half (flipped!)

# vectorize matrices
pixL <- as.vector(stimL)
pixR <- as.vector(stimR)

# estimate percentage of pixels being identical
mean(pixL == pixR)

# -- Note: if you want to allow for a little bit of noise in the image,
#          define a noise threshold and compare the pixel differences against
#          this threshold
noise = .01
mean(abs(pixL - pixR) < noise)


# horizontal symmetry (top vs bottom)
# -- Note: here, we just rotate the image by 90 degrees, thereby allowing to
#          remain the rest of the code the same
img = OpenImageR::RGB_to_HSV(imagefluency::rotate90(img_red))[,,1] # keep only HUE

imgW <- dim(img)[2]
stimL <- img[, 1:floor(imgW / 2)]
stimR <- img[, imgW:(1 + ceiling(imgW / 2))]

pixL <- as.vector(stimL)
pixR <- as.vector(stimR)

mean(pixL == pixR)

As for the rotation of the symmetry axis: I completely agree, this would be a nice feature. Unfortunately, this is not trivial. I may incorporate this option in the future.

from imagefluency.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.