joergdietrich / daltonize Goto Github PK
View Code? Open in Web Editor NEWSimulate and correct images for dichromatic color blindness
License: GNU General Public License v2.0
Simulate and correct images for dichromatic color blindness
License: GNU General Public License v2.0
Fixing the invariant to red for tritanopia (#15 ) seems to break the correction transformation for daltonization of tritanopia.
I know this is an old repo but this is still being used by several developers (including me).
I noticed that on a 2GB linux machine , MemoryError
is raised when converting a 2-3MB image (3933 x 5906 pixels in size). Here is a truncated error message.
File "./<app>/daltonize.py", line 132, in simulate_from_image
rgb = np.asarray(img, dtype=float)
File "/root/.cache/pypoetry/virtualenvs/<path>/lib/python3.6/site-packages/numpy/core/_asarray.py", line 85, in asarray
return array(a, dtype, copy=False, order=order)
MemoryError: Unable to allocate 532. MiB for an array with shape (3933, 5906, 3) and data type float64
This is very weird that for a 3MB file, it requires a large 532MB amount of memory.
Related line on this repo: https://github.com/joergdietrich/daltonize/blob/master/daltonize.py#L79
The RGB-LMS conversion matrices and color blindness matrices used by this repo are very different from those listed on https://ixora.io/projects/colorblindness/color-blindness-simulation-research/ (which you mentioned you consulted in #13), and also those in the original MATLAB file in https://github.com/joergdietrich/daltonize/blob/master/doc/conv_img.m.
I'm quite confused why these are all different. Could you maybe shed some light on this?
On my Ubuntu 20.04 with Python 3.8.10 and numpy 1.21.3 I always get black images out of the simulation
function (all values are zero). numpy 1.20.3 works fine, the problem started with numpy 1.21.0.
The guilty part is transform_colorspace
, where the np.einsum("ij, ...j", mat, img, dtype=np.float16, casting="same_kind")
always returns 0 when given rgb2lms as input, unless dtype
is changed back to np.float32
. As a consequence this also breaks the daltonization, which becomes a noop.
I'm not sure if this is actually a numpy bug, but an alternative solution is to return img @ mat.T
, which is equivalent to the einsum
thanks to numpy broadcasting rules, but still works with float16. It may also be a bit faster.
Going back to float32 might be a safer choice too!
I get the following error when I run the program on a 800x600 PNG image:
ValueError: operand 0 did not have enough dimensions to match the broadcasting, and couldn't be extended because einstein sum subscripts were specified at both the start and end
/home/joerg/src/daltonize/daltonize.py:251: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if color == 'none':
/home/joerg/src/daltonize/daltonize.py:316: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if color == 'none':
/home/joerg/applications/anaconda3/lib/python3.6/site-packages/matplotlib/lines.py:1182: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if self._markeredgecolor != ec:
/home/joerg/applications/anaconda3/lib/python3.6/site-packages/matplotlib/lines.py:1206: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if self._markerfacecolor != fc:
Hello,
This script gives me different results from other color blindness simulator.
Steps to reproduce:
Expectation:
The results are the same
Actual:
The results are very different
Data image used:
The simulation function for color vision deficiency doesn't work for the current matplotlib version (3.5.1).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.