Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add deltaE functions and lab2lch color conversion utils - #665

Merged
jni merged 36 commits into
scikit-image:masterfrom
mrterry:deltae
Aug 18, 2013
Merged

Add deltaE functions and lab2lch color conversion utils#665
jni merged 36 commits into
scikit-image:masterfrom
mrterry:deltae

Conversation

@mrterry

@mrterry mrterry commented Jul 24, 2013

Copy link
Copy Markdown
Contributor

Adds four color distance metrics CIE76, CIEDE94, CIEDE2000, and CMC. Docs and tests included. The deltaE functions should work so long as the two color arrays are conformable. ie deltaE(x, y) works for x.shape == (3,); y.shape = (10, 10, 3) as well as when they have the same shape.

It also adds lab2lch (lch2lab) color conversion functions. These were needed for some of the deltaE functions, but are not actually called internally.

Comment thread skimage/color/colorconv.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past I believe we allowed or even preferred this syntax, but more recently we've moved to preferring PEP8 style generally (with spaces on either side of all operators, including **).

There are a few other places where spaces should be added around e.g. *. Running flake8 on these will show you where. Also, if it results in a bad line break or poor readability feel free to defend non-PEP8 syntax - PEP8 itself says it's meant to be broken ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i personally like tightly bound operators tightly spaced (especially **), but not a big deal and easily easily fixed.

@JDWarner

Copy link
Copy Markdown
Contributor

This looks great, thanks! Other than the minor comments above, I think it should be possible to break the references to roughly 80 characters.

@mrterry

mrterry commented Jul 24, 2013

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I made the requested changes.

Comment thread skimage/color/colorconv.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you split these into two separate lines, respectively?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will cost you a temporary array.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, also applies to other occurrences.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now! No need then.

@jni

jni commented Aug 8, 2013

Copy link
Copy Markdown
Member

I've never actually attempted building the docs, and I don't think I'm doing it right. @mrterry, can you tell me how to get from checking out your branch to the error you're having trouble with?

@mrterry

mrterry commented Aug 8, 2013

Copy link
Copy Markdown
Contributor Author

I'm not positive I'm doing it right either : ) Here is what I'm doing:

git clone https://github.com/mrterry/scikit-image -b deltae skimage_clean
cd skimage_clean
python setup.py install  # docs need to be able to __import__('skimage')
cd doc
make html
< buiding >
reading sources... [ 12%] api/skimage.measure
Sphinx error:
'ascii' codec can't encode character u'\u2013' in position 1307: ordinal not in range(128)
make: *** [html] Error 1

unichr(0x2013) is a hyphen-like character "–" which occurs in skimage/filter/_denoise_cy.pyx If you replace them with ascii dashes, re-install, and re-build doc, sphinx starts complaining about other unicode. ä, ü, and presumably more.

@jni

jni commented Aug 12, 2013

Copy link
Copy Markdown
Member

@mrterry, just to be clear, your doc fails only at that spot? ie, is there any more output after that "Error 1"? Because I get a lot of apparent errors, I think to do with missing plugins in my test box, and I can't even find the unicode error you mentioned. Do you have the right version of sphinx?

Here's my build blatantly stepping right over your error: =P

reading sources... [  1%] api/api
reading sources... [  2%] api/skimage
reading sources... [  3%] api/skimage.color
reading sources... [  4%] api/skimage.data
reading sources... [  5%] api/skimage.draw
reading sources... [  6%] api/skimage.exposure
reading sources... [  7%] api/skimage.feature
/home/ubuntu/projects/scikit-image/doc/source/../ext/docscrape.py:118: UserWarning: Unknown section (imxx * Imy**2 + Imyy * Imx**2 - 2 * Imxy * Imx * Imy)
  warn("Unknown section %s" % key)
reading sources... [  8%] api/skimage.filter
reading sources... [  9%] api/skimage.filter.rank
/home/ubuntu/projects/scikit-image/doc/source/../ext/docscrape.py:118: UserWarning: Unknown section Note
  warn("Unknown section %s" % key)
reading sources... [ 10%] api/skimage.graph
reading sources... [ 11%] api/skimage.io
reading sources... [ 13%] api/skimage.io._plugins
reading sources... [ 14%] api/skimage.measure
/home/ubuntu/projects/scikit-image/doc/source/../ext/docscrape.py:118: UserWarning: Unknown section Example
  warn("Unknown section %s" % key)
reading sources... [ 15%] api/skimage.morphology
reading sources... [ 16%] api/skimage.segmentation

And here it is finally croaking:

writing output... [  8%] api/skimage.filter
writing output... [  9%] api/skimage.filter.rank

Exception occurred:
  File "/home/ubuntu/.virtualenvs/scikit-image-dev/local/lib/python2.7/site-packages/docutils/nodes.py", line 954, in replace_self
    'Losing "%s" attribute: %s' % (att, self[att])
AssertionError: Losing "ids" attribute: ['id1']
The full traceback has been saved in /tmp/sphinx-err-PTVaYV.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
Either send bugs to the mailing list at <http://groups.google.com/group/sphinx-users/>,
or report them in the tracker at <http://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!
make: *** [html] Error 1

@stefanv @ahojnnes @tonysyu @josteinbf, I'm assuming you have built the doc before and have an environment properly set up to do so. Could you try checking out @mrterry's branch and building the docs, see if you can reproduce this error? Other than that, imho this is ready to merge.

@josteinbf

Copy link
Copy Markdown
Contributor

@jni The docs build at my setup, but with a lot of warnings (normal, but bad). None of the warnings mention the word "color", so I suppose none of the warnings are from the color package. On the other hand, I cannot find neither lab2lch nor lch2lab in the generated docs, so there is certainly a problem somewhere.

Let me know if you want to see the full sphinx log or need to know more about my setup.

@mrterry

mrterry commented Aug 12, 2013

Copy link
Copy Markdown
Contributor Author

@jni Something in my environment was borked. I see the same error you do. Upon further investigation, it appears to be a problem in the latest sphinx.

With sphinx 1.2b, my master, my branch, and my branch's master-parent fail to build the docs.
With sphinx 1.1, build succeeds

@stefanv

stefanv commented Aug 12, 2013

Copy link
Copy Markdown
Member

Yikes! Is this due to an abuse on our side, or is Sphinx now broken?

@mrterry

mrterry commented Aug 12, 2013

Copy link
Copy Markdown
Contributor Author

I'm going to blame sphinx. I found this suspicious looking (solved) bug report, but it isn't in the 1.2b release on PyPI. Somewhat OT, but it seems a little fishy for pip install sphinx to give you a beta release.

@mrterry

mrterry commented Aug 12, 2013

Copy link
Copy Markdown
Contributor Author

@josteinbf When I build the docs (with sphinx-1.1), all the new functions show up in the docs. Did you build & install my branch? I think the docs build script looks at import skimage, rather than ../skimage

@ahojnnes

Copy link
Copy Markdown
Member

I experienced the same issues some months ago... as far as I can remember it is caused by a bug in Sphinx.

@josteinbf

Copy link
Copy Markdown
Contributor

@mrterry Sorry, it was a stupid mistake (although not the one you suggested). It is working as it should (sphinx 1.1.3).

@jni

jni commented Aug 14, 2013

Copy link
Copy Markdown
Member

@josteinbf, are you saying you have successfully built the docs on this branch? I haven't, but I haven't successfully built the docs on any branch. ;) Other than that, the tests, coverage, functionality, and syntax are ready, as far as I'm concerned.

If anyone can tell me why I'm getting a buttload of errors such as this one when building the docs, I'd be eternally grateful. =)

Exception raised while running:
plot_rank_filters.py in /home/ubuntu/projects/scikit-image/doc/source/../examples/applications
\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Traceback (most recent call last):
  File "/home/ubuntu/projects/scikit-image/doc/source/../ext/plot2rst.py", line 253, in write_gallery
    write_example(src_name, src_dir, rst_dir, cfg)
  File "/home/ubuntu/projects/scikit-image/doc/source/../ext/plot2rst.py", line 325, in write_example
    figure_list, rst = process_blocks(blocks, src_path, image_path, cfg)
  File "/home/ubuntu/projects/scikit-image/doc/source/../ext/plot2rst.py", line 493, in process_blocks
    exec(bcontent, example_globals)
  File "<string>", line 12, in <module>
  File "/home/ubuntu/.virtualenvs/scikit-image-dev/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 2892, in imshow
    imlim=imlim, resample=resample, url=url, **kwargs)
  File "/home/ubuntu/.virtualenvs/scikit-image-dev/local/lib/python2.7/site-packages/matplotlib/axes.py", line 7299, in imshow
    im.set_data(X)
  File "/home/ubuntu/.virtualenvs/scikit-image-dev/local/lib/python2.7/site-packages/matplotlib/image.py", line 425, in set_data
    raise TypeError("Image data can not convert to float")
TypeError: Image data can not convert to float
\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(Incidentally the backslashes in front of the tilde line breaks are mine, otherwise the markdown doesn't render properly... Something else to troubleshoot!)

@josteinbf

Copy link
Copy Markdown
Contributor

@jni Yes, I successfully built the docs for both this branch and master.
The functionality added by this branch does show up in the docs, as far as
I can tell. I can't vouch for the contents, though.

2013/8/14 Juan Nunez-Iglesias [email protected]

@josteinbf https://github.com/josteinbf, are you saying you have
successfully built the docs on this branch? I haven't, but I haven't
successfully built the docs on any branch. ;) Other than that, the
tests, coverage, functionality, and syntax are ready, as far as I'm
concerned.

If anyone can tell me why I'm getting a buttload of errors such as this
one when building the docs, I'd be eternally grateful. =)

Exception raised while running:plot_rank_filters.py in /home/ubuntu/projects/scikit-image/doc/source/../examples/applications

  File "/home/ubuntu/projects/scikit-image/doc/source/../ext/plot2rst.py", line 253, in write_gallery
    write_example(src_name, src_dir, rst_dir, cfg)
  File "/home/ubuntu/projects/scikit-image/doc/source/../ext/plot2rst.py", line 325, in write_example
    figure_list, rst = process_blocks(blocks, src_path, image_path, cfg)
  File "/home/ubuntu/projects/scikit-image/doc/source/../ext/plot2rst.py", line 493, in process_blocks
    exec(bcontent, example_globals)
  File "<string>", line 12, in <module>
  File "/home/ubuntu/.virtualenvs/scikit-image-dev/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 2892, in imshow
    imlim=imlim, resample=resample, url=url, **kwargs)
  File "/home/ubuntu/.virtualenvs/scikit-image-dev/local/lib/python2.7/site-packages/matplotlib/axes.py", line 7299, in imshow
    im.set_data(X)
  File "/home/ubuntu/.virtualenvs/scikit-image-dev/local/lib/python2.7/site-packages/matplotlib/image.py", line 425, in set_data
    raise TypeError("Image data can not convert to float")TypeError: Image data can not convert to float
\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(Incidentally the backslashes in front of the tilde line breaks are mine,
otherwise the markdown doesn't render properly... Something else to
troubleshoot!)

—
Reply to this email directly or view it on GitHubhttps://github.com/scikit-image/scikit-image/pull/665#issuecomment-22611578
.

@jni

jni commented Aug 15, 2013

Copy link
Copy Markdown
Member

Hmm, I was just about to push the merge button but I ran a merge+test... Nothing major but some warnings... @mrterry, any idea what's causing them and whether they can be easily avoided?

nuneziglesiasj@jni-lscc-mbp Thu Aug 15 15:17
 ~/projects/skimage (deltae-merge)$ nosetests --no-skip
Exception AttributeError: "'UmfpackContext' object has no attribute '_symbolic'" in <bound method UmfpackContext.__del__ of <scipy.sparse.linalg.dsolve.umfpack.umfpack.UmfpackContext object at 0x108e34090>> ignored
............................................/Volumes/Projects/skimage/skimage/color/delta_e.py:111: RuntimeWarning: invalid value encountered in sqrt
  dH = np.sqrt(deltaE_cie76(lab1, lab2) ** 2 - dL ** 2 - dC ** 2)
../Volumes/Projects/skimage/skimage/color/delta_e.py:292: RuntimeWarning: invalid value encountered in sqrt
  dH = np.sqrt(deltaE_cie76(lab1, lab2) ** 2 - dL ** 2 - dC ** 2)
.............................................................................................................../Volumes/Projects/skimage/skimage/filter/rank/generic.py:63: UserWarning: Bitdepth of 11 may result in bad rank filter performance due to large number of bins.
  "performance due to large number of bins." % bitdepth)
................../Volumes/Projects/skimage/skimage/filter/rank/generic.py:63: UserWarning: Bitdepth of 12 may result in bad rank filter performance due to large number of bins.
  "performance due to large number of bins." % bitdepth)
/Volumes/Projects/skimage/skimage/filter/rank/generic.py:63: UserWarning: Bitdepth of 13 may result in bad rank filter performance due to large number of bins.
  "performance due to large number of bins." % bitdepth)
/Volumes/Projects/skimage/skimage/filter/rank/generic.py:63: UserWarning: Bitdepth of 14 may result in bad rank filter performance due to large number of bins.
  "performance due to large number of bins." % bitdepth)
/Volumes/Projects/skimage/skimage/filter/rank/generic.py:63: UserWarning: Bitdepth of 15 may result in bad rank filter performance due to large number of bins.
  "performance due to large number of bins." % bitdepth)
................................................................................................../Volumes/Projects/skimage/skimage/exposure/exposure.py:51: UserWarning: This might be a color image. The histogram will be computed on the flattened image. You can instead apply this function to each color channel.
  warnings.warn("This might be a color image. The histogram will be "
...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 802 tests in 64.675s

OK

@jni

jni commented Aug 15, 2013

Copy link
Copy Markdown
Member

Oh, and it looks like a function in the tests is misspelled: test_single_color_cidede94, which is one of the functions throwing up warnings. The other one is test_single_color_cmc.

@mrterry

mrterry commented Aug 15, 2013

Copy link
Copy Markdown
Contributor Author

The warning is a sqrt(negative zero) that shows up when comparing two
identical colors. It is harmless, but I'll bang on I this afternoon.
On Aug 14, 2013 10:40 PM, "Juan Nunez-Iglesias" [email protected]
wrote:

Oh, and it looks like a function in the tests is misspelled:
test_single_color_cidede94, which is one of the functions throwing up
warnings. The other one is test_single_color_cmc.


Reply to this email directly or view it on GitHubhttps://github.com//pull/665#issuecomment-22686216
.

@mrterry

mrterry commented Aug 15, 2013

Copy link
Copy Markdown
Contributor Author

Apparently this was more interesting than the work I was supposed be doing. : ) This change fixes the roundoff issues that were showing up for identical colors. It should be faster and more memory efficient too.

@jni

jni commented Aug 17, 2013

Copy link
Copy Markdown
Member

@mrterry,

Apparently this was more interesting than the work I was supposed be doing. : )

definitely been there! ;)

Question: why do you compute dH2 as dLab2 - dL2 - dC2, or, in the new code, as da2 + db2 - dC**2, instead of just getting H from the lab2lch conversion and computing the difference directly?

I'm asking because it took me a while to figure out what you were doing, and I'm hoping to save future maintainers the same effort. So I would either:

  • compute dH directly from the lab2lch conversion, or
  • write in the get_dH docstring why this way is better, and, rather than use a1, b1 etc in the docstring then switch to r1 and r2 in the function body, adopt a unified naming convention between the two.

Sorry to be nitpicky, but I think the improved clarity will be worth it...!

@mrterry

mrterry commented Aug 17, 2013

Copy link
Copy Markdown
Contributor Author

@jni,
the new docstring should describe why I do things the way I do. The long answer is that the papers I'm pulling from describe everything in terms of components, when vectors would be much more clear. You just got a front row seat to me cleaning it all up.

@jni

jni commented Aug 18, 2013

Copy link
Copy Markdown
Member

Very nice! All tests pass with no warnings and the code is much clearer. (to me at least!) Thanks for sticking with it!

Incidentally, you wrote "working directly with the hue value directly", but I'll let you fix that in a separate PR, this one has dragged on long enough. =)

jni added a commit that referenced this pull request Aug 18, 2013
Add deltaE functions and lab2lch color conversion utils
@jni
jni merged commit b6f72c6 into scikit-image:master Aug 18, 2013
@mrterry

mrterry commented Aug 19, 2013

Copy link
Copy Markdown
Contributor Author

thanks!

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 this pull request may close these issues.

6 participants