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

Add `label2rgb` #485

Merged
merged 7 commits into from Jun 23, 2013

Conversation

Projects
None yet
4 participants
@tonysyu
Copy link
Member

tonysyu commented Mar 30, 2013

This PR adds a function to overlay colorized labels on top of an image. You can see the results of this function in the modified plot_join_segmentations.py example.

Not included in the example: You can also use a matplotlib colormap to choose colors. For example:

colors = plt.cm.Set1(np.linspace(0, 1, 12))
colorized = label2rgb(label, image=image, colors=colors)
@stefanv

This comment has been minimized.

Copy link
Member

stefanv commented Mar 31, 2013

@tonysyu This is very nice! Could you also have a look at #428 and see if there is any common functionality that can be pulled out?

@tonysyu

This comment has been minimized.

Copy link
Member

tonysyu commented Mar 31, 2013

Do you mean the color definitions? That should be easy---just a couple of API decisions:

  • RGB floats vs uint8
  • color dict vs module variables
    If PR #428 is going to be merged soon, I can consolidate the color defs afterwards---either in this PR or in a separate PR.
from numpy.distutils.misc_util import Configuration

config = Configuration('color', parent_package, top_path)
config.add_data_files('colors.ini')

This comment has been minimized.

@stefanv

stefanv Apr 1, 2013

Member

Should the Bento file also be updated?

This comment has been minimized.

@tonysyu

tonysyu Apr 2, 2013

Member

Good point. My first reaction was to look for where the plugin *.ini files were added, but I don't see those in bento.info. Am I missing something?

@tonysyu

This comment has been minimized.

Copy link
Member

tonysyu commented May 6, 2013

Update: I ended up changing the API to the function. image_label2rgb is now named label2rgb and more importantly, the input image is now an optional argument (which required switching the order of the first 2 arguments). Now the function behaves like the matlab equivalent when no image is given, but has the added bonus of an image underlay (when specified).

Also, I rebased the branch because of merge conflicts.

'indigo', 'darkorange', 'cyan', 'pink', 'yellowgreen')


def _load_colors():

This comment has been minimized.

@stefanv

stefanv May 6, 2013

Member

Why don't we just strip out the first line of colors.ini, make it a .py, and then import it and use its namespace as dictionary?

This comment has been minimized.

@tonysyu

tonysyu May 7, 2013

Member

Hmm, I guess I've just internalized the idea that it's best to keep data in data files, not python modules. But I guess that applies more to configuration data than to application data.

Is the idea here to have the colors available both as module attributes and a dict?

This comment has been minimized.

@stefanv

stefanv May 28, 2013

Member

I just thought it would be an easy way to get syntax checking for free, and to avoid having to have a loader function,

@tonysyu tonysyu referenced this pull request May 26, 2013

Closed

Re-added novice module #521

Change color definitions from ini file to python module
This simplifies the code and allows users to use either `color_dict` or module
variables, e.g., `rgb_colors.white`.
@tonysyu

This comment has been minimized.

Copy link
Member

tonysyu commented Jun 20, 2013

@stefanv I finally got around to implementing your suggestion of switching from defining colors in a python module instead of an ini file, and it did indeed simplify things quite a bit.

One last thing I'm uncertain about: Does it make sense to name the kwarg image, or should it be more explicit, like underlay. The later better describes what the kwarg does, but might be a bit more difficult to parse (mentally).

@ahojnnes

This comment has been minimized.

Copy link
Member

ahojnnes commented Jun 20, 2013

I personally find image better… apart from that I think this is ready to merge.

This was referenced Jun 21, 2013

@ahojnnes

This comment has been minimized.

Copy link
Member

ahojnnes commented Jun 21, 2013

Addition: I would use uppercase names for the colors.

@tonysyu

This comment has been minimized.

Copy link
Member

tonysyu commented Jun 22, 2013

As for the kwarg name, I think I agree, so I'll leave it as-is.

As for uppercase names, I'm not sure if I agree. I understand the reasons (PEP8 compatibility, globals should be easily identifiable, etc.). That said, I think it makes the names quite-a-bit-less readable. That's my perspective, but I'm happy to change it if others feel strongly about it.

Also, right now, the names are the same as Matplotlib (not that I think Matplotlib is necessarily a good model for everything, but it might be nice to be able to switch back-and-forth).

@jni

This comment has been minimized.

Copy link
Contributor

jni commented Jun 22, 2013

I'm not a fan of all-uppercase names either.

stefanv added a commit that referenced this pull request Jun 23, 2013

@stefanv stefanv merged commit 0a727e3 into scikit-image:master Jun 23, 2013

1 check passed

default The Travis CI build passed
Details
@stefanv

This comment has been minimized.

Copy link
Member

stefanv commented Jun 23, 2013

@tonysyu Thanks--so many colors! With this merged, we can move on to the novice module.

jni added a commit to jni/scikit-image that referenced this pull request Apr 12, 2018

Remove negative intensity warning in label2rgb
This warning appears to have been adopted in scikit-image#485 with no discussion at
all. imho it is unnecessary: if we want to support negative intensity,
we should do it correctly (fixing the intensity), rather than raising a
warning and doing nothing (since the function silently succeeds).

Refs: scikit-image#485
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment