Comments (1)
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.
The following code results in horizontal symmetry values of 0.99 for both images. The steps are:
- first convert the RGB images into the HSV color space (hue, saturation, value)
- then only use the information on the hue channel (i.e., the color information)
- 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)
- Error: Could not find shiny app directory. Try re-installing `imagefluency`. HOT 1
- Error: Invalid input (should be a matrix or a 3-dimensional array of numeric or integer values) HOT 4
- Images in getting started vignette are not displayed on github.io page
- Wrong code in batch-processing vignette
- imagefluency package is not working HOT 3
- Incorrect parameter name in documentation: function .compl()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imagefluency.