embl-cba / DNA-FISH

0 stars 0 forks source link

Colour spots #12

Closed tischi closed 1 year ago

tischi commented 1 year ago
          We would need to store what channels are the spots created on. 

But I think the fastest way would be to directly use the MANUAL_COLOR feature. Here you just specify what color you want to use, specified as an int.

https://github.com/trackmate-sc/TrackMate/blob/master/src/main/java/fiji/plugin/trackmate/features/manual/ManualSpotColorAnalyzerFactory.java

It's one of the lesser known feature of TrackMate but could be a perfect fit if you are ok to specify color 'manually' in your code.

Screenshot 2023-06-07 at 12 59 23

Originally posted by @tinevez in https://github.com/tischi/fiji-plugin-FISH/issues/11#issuecomment-1580529939

tischi commented 1 year ago

@tinevez I need your help; I don't know how to use your suggestion above.

I have a feeling it should go somewhere in the code that follows here but I really don't know where to start....

Essentially I don't understand how to use ManualSpotColorAnalyzerFactory in my code.

tinevez commented 1 year ago

Ah you don't have to use it. You just set the manual color feature of a spot using the String key, and the UI will be able to take it from there. This is how manual color is set in TrackScheme:

https://github.com/trackmate-sc/TrackMate/blob/master/src/main/java/fiji/plugin/trackmate/visualization/trackscheme/TrackSchemePopupMenu.java#LL93C1-L95C69

tischi commented 1 year ago

I think I did it but all spots are still painted in magenta...

Do I have to "activate" the colouring somewhere?

tinevez commented 1 year ago

Yes! It's done when you prepare the view: You would specify to color the spots using the manual spot color. Like this:

DisplaySettings ds = DisplaySettings.defaultStyle();
ds.setTrackVisible( false );
ds.setSpotVisible( true );
ds.setSpotDisplayRadius( 2. );
ds.setHighlightColor( Color.BLUE );
ds.setSpotColorBy( TrackMateObject.SPOTS, ManualSpotColorAnalyzerFactory.FEATURE );

(the last one is important)

Then you pass the DisplaySettings ds to the view when you create it:

final HyperStackDisplayer view = new HyperStackDisplayer( model, selectionModel, imp, ds );
view.render();

If you modify ds after creating the view, the view will be updated.

tischi commented 1 year ago

Yeah, that works! Thank you so much ❤️ !

image
tischi commented 1 year ago

Maybe interesting for you: I also managed now to colour the spots in the same colour as the channel of the image.

    private Map< Integer, Color > createChannelIndexToColorMap()
    {
        final CompositeImage compositeImage = ( CompositeImage ) (imp);
        final int nChannels = compositeImage.getNChannels();
        Map< Integer, Color > channelIndexToColor = new HashMap<>();
        final LUT[] luts = compositeImage.getLuts();
        for ( int channelIndex = 0; channelIndex < nChannels; channelIndex++ )
        {
            IndexColorModel cm = luts[ channelIndex ];
            int index = cm.getMapSize() - 1;
            int r = cm.getRed(index);
            int g = cm.getGreen(index);
            int b = cm.getBlue(index);
            final Color color = new Color( r, g, b );
            channelIndexToColor.put( channelIndex+1, color );
        }
        return channelIndexToColor;
    }