imagej / imagej-legacy

ImageJ+ImageJ2 compatibility layer
https://imagej.net/libs/imagej-legacy
BSD 2-Clause "Simplified" License
17 stars 25 forks source link

Edits to ColorTables of ImagePlus created from a Dataset never make it back to that Dataset #311

Open gselzer opened 2 hours ago

gselzer commented 2 hours ago

@ctrueden provided me with a script that can be run in Fiji-future with a SNAPSHOT scijava/scripting-python jar, which does the following:

LegacyImageMap makes a Harmonizer object on events - is there a reason why it cannot have one of these all the time, such that syncrhonizeAttachmentsToDataset could utilize it?

ctrueden commented 1 hour ago

The reason is that trying to keep ImagePlus and ImageDisplay objects in sync completely is a wild goose chase. Some data structures like the color tables are not wrapped but rather copied, and knowing under which circumstances exactly to trigger automatic sync is fraught: if you do it too often there is a potentially severe performance hit, and if you do it not often enough then things get out of sync. So in recent years we have not tried to improve this. My preference would be to actually back off the syncing approach altogether in favor of code wanting to utilize both kinds of data structures doing it themselves.

gselzer commented 1 hour ago

Some data structures like the color tables are not wrapped but rather copied,

Looking a bit at the API, I'm not sure I understand why they couldn't be wrapped - is there a reason that you know?

My preference would be to actually back off the syncing approach altogether in favor of code wanting to utilize both kinds of data structures doing it themselves.

Well, then at the very least we need to expose the logic that is used to perform the conversion, namely Converter plugins that go between ij.process.LUTs and net.imglib2.display.ColorTables.

On a broader scale though, I'm not sure what you mean by "code wanting to utilize both data structures". This repository, pyimagej/napari-imagej, and the example script listed above are all versions of such. If you really think the synchronization code does not belong here, maybe pyimagej is the correct place for this, within ij.py.sync_image? It's really unfortunate, though, that some of the synchronization code is there, and more is here...or do you think the script author should be doing the synchronization?