Skip to content
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

Create plug-ins to convert well-known text to bitmasks and vice versa #14

Merged
merged 2 commits into from
Apr 20, 2021

Conversation

charismatic-claire
Copy link

Suppose you created a segmentation using the Image Processing environment in KNIME. You can extract all the segments from your segmentation and get a list of bitmasks. Wouldn't it be great to convert this bitmask representation of the segments to a well-known text (*.wkt) representation. Why? Because it,s more universal.

And why not go the other way round too? Suppose you have an image and a list of segments in well-known text (*.wkt) format. It should be possible to convert those to bitmasks that can be used to assemble an image segmentation using KNIME's GroupBy node.

Here is the corresponding thread in the KNIME forum: Convert Well-Known Text (WKT) To Labeling

Copy link
Member

@imagejan imagejan left a comment

Choose a reason for hiding this comment

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

Thanks, @charismatic-claire, for the awesome contribution!

I left some comments, mostly clarifying licensing, and cosmetic changes (menu path, README, etc.).

If you're fine with it, I'll probably merge this within the next days.

Comment on lines +23 to +34
| [`AnalyzeSkeleton_`](https://github.com/fiji/AnalyzeSkeleton/) | [`AnalyzeSkeleton_-3.4.2.jar`](http://maven.imagej.net/service/local/repositories/releases/content/sc/fiji/AnalyzeSkeleton_/3.4.2/AnalyzeSkeleton_-3.4.2.jar) |
| [`Descriptor_based_registration`](https://github.com/fiji/Descriptor_based_registration) | [`Descriptor_based_registration-2.1.7.jar`](http://maven.imagej.net/service/local/repositories/releases/content/sc/fiji/Descriptor_based_registration/2.1.7/Descriptor_based_registration-2.1.7.jar) |
| [`Fiji_Plugins`](https://github.com/fiji/Fiji_Plugins) | [`Fiji_Plugins-3.1.1.jar`](http://maven.imagej.net/service/local/repositories/releases/content/sc/fiji/Fiji_Plugins/3.1.1/Fiji_Plugins-3.1.1.jar) |
| [`fmi-trackmate-addons`](https://github.com/fmi-faim/fmi-trackmate-addons) | [`fmi-trackmate-addons-0.1.2.jar`](http://maven.imagej.net/service/local/repositories/releases/content/ch/fmi/fmi-trackmate-addons/0.1.2/fmi-trackmate-addons-0.1.2.jar) |
| [`guava`](https://github.com/google/guava) | [`guava-21.0.jar`](http://maven.imagej.net/service/local/repositories/central/content/com/google/guava/guava/21.0/guava-21.0.jar) |
| `jdom2` | [`jdom2-2.0.6.jar`](http://maven.imagej.net/service/local/repositories/bedatadriven/content/org/jdom/jdom2/2.0.6/jdom2-2.0.6.jar) |
| [`jgrapht-core`](https://github.com/jgrapht/jgrapht) | [`jgrapht-core-1.3.0.jar`](http://maven.imagej.net/service/local/repositories/central/content/org/jgrapht/jgrapht-core/1.3.0/jgrapht-core-1.3.0.jar) |
| [`jgrapht-core`](https://github.com/jgrapht/jgrapht) | [`jgrapht-core-1.4.0.jar`](http://maven.imagej.net/service/local/repositories/central/content/org/jgrapht/jgrapht-core/1.4.0/jgrapht-core-1.4.0.jar) |
| [`jts-core`](https://github.com/locationtech/jts) | [`jts-core-1.18.1.jar`](https://repo.maven.apache.org/maven2/org/locationtech/jts/jts-core/1.18.1/jts-core-1.18.1.jar) |
| [`legacy-imglib1`](https://github.com/fiji/legacy-imglib1) | [`legacy-imglib1-1.1.9.jar`](http://maven.imagej.net/service/local/repositories/releases/content/sc/fiji/legacy-imglib1/1.1.9/legacy-imglib1-1.1.9.jar) |
| [`mpicbg`](https://github.com/axtimwalde/mpicbg/tree/master/mpicbg) | [`mpicbg-1.3.0.jar`](http://maven.imagej.net/service/local/repositories/releases/content/mpicbg/mpicbg/1.3.0/mpicbg-1.3.0.jar) |
| [`SPIM_Registration`](https://github.com/fiji/SPIM_Registration) | [`SPIM_Registration-5.0.19.jar`](http://maven.imagej.net/service/local/repositories/releases/content/sc/fiji/SPIM_Registration/5.0.19/SPIM_Registration-5.0.19.jar) |
| [`TrackMate_`](https://github.com/fiji/TrackMate) | [`TrackMate_-4.0.0.jar`](http://maven.imagej.net/service/local/repositories/releases/content/sc/fiji/TrackMate_/4.0.0/TrackMate_-4.0.0.jar) |
| [`mpicbg`](https://github.com/axtimwalde/mpicbg/tree/master/mpicbg) | [`mpicbg-1.4.1.jar`](http://maven.imagej.net/service/local/repositories/releases/content/mpicbg/mpicbg/1.4.1/mpicbg-1.4.1.jar) |
| [`SPIM_Registration`](https://github.com/fiji/SPIM_Registration) | [`SPIM_Registration-5.0.21.jar`](http://maven.imagej.net/service/local/repositories/releases/content/sc/fiji/SPIM_Registration/5.0.21/SPIM_Registration-5.0.21.jar) |
| [`TrackMate_`](https://github.com/fiji/TrackMate) | [`TrackMate_-6.0.1.jar`](http://maven.imagej.net/service/local/repositories/releases/content/sc/fiji/TrackMate_/6.0.1/TrackMate_-6.0.1.jar) |
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for updating these. I think I should remove this listing entirely from the README, since it gets out of sync too easily. The versions shipped via the FMI KNIME update site are defined in this other repository here:

https://github.com/fmi-faim/fmi-knime-update-site/tree/cd19f869ce2be57004e1d3b45d267e73b7d2d7e1/ch.fmi.knime.plugins/lib

So this README is only in case you manually install the jar file into the ImageJ integration. Leaving away the versions is probably fine.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah sure, I'm fine with that. So I'll just leave it as is and it can be updated with the next release on master, right?

Comment on lines 2 to 7
* #%L
* Plug-in to convert a 2D binary to a polygon geometry serialized to
* well-known text (wkt).
* %%
* @author Charismatic Claire
* %%
Copy link
Member

Choose a reason for hiding this comment

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

We usually generate the license headers by running mvn license:update-file-header before each release, which will replace the copyright statement by the content from the pom.xml. I hope you're ok if this information gets replaced? The Friedrich Miescher Institute (FMI) legally is the copyright owner of this software, as it is being developed as part of my work at FMI.

Your authorship is of course unaffected, and will be visible from the git history. We can also add a class javadoc containing an @author tag. Would you be ok adding your real name in such a tag?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I changed that accordingly. I haven't decided about my real name being put somewhere in the code. So I think I just skip that part for now.

Comment on lines 71 to 72
else throw new Exception(
String.format("Your envelop <%s> stems from another world!", envelope.toText()));
Copy link
Member

Choose a reason for hiding this comment

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

🙂 maybe throw a more specific RuntimeException (or IllegalArgumentException) here?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah sure, I added an IllegalArgumentException.

output = image;
} catch (ParseException e) {
logService.warn(String.format("Could not create a polygon from input <{}>", text));
} catch(Exception e) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we catch a more specific Exception here?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah sure, I added an IllegalArgumentException.

import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

@Plugin(type = Command.class, headless = true, menuPath = "FMI>2D Binary Mask To Text")
Copy link
Member

Choose a reason for hiding this comment

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

I might take the opportunity and refine the menu structure a bit. Currently, all plugins from this repository are listed under a single FMI menu. It would make sense to create sub-menus for working with shapes, tracks, segmentations etc.

I will probably work on this before the next release, but if you have ideas or comments, I'm open for suggestions 😉

Copy link
Author

Choose a reason for hiding this comment

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

I think I'll leave that to you since I only know what 3 plug-ins are doing :-)

@imagejan imagejan self-assigned this Mar 24, 2021
@charismatic-claire
Copy link
Author

Any news on when the new version of the KNIME plug-in will be released? We are already using my new plug-in but it would be much easier to deploy if we had it upstream, of course ^^

@imagejan
Copy link
Member

imagejan commented Apr 8, 2021

Sorry for the delay, @charismatic-claire, I'll try to cut a new release within the next couple of days!

Charismatic Claire and others added 2 commits April 20, 2021 12:03
@imagejan imagejan force-pushed the issue-13-wkt-bitmask branch from 66e1a29 to b06e5e6 Compare April 20, 2021 10:08
@imagejan imagejan merged commit 7de8ad3 into fmi-faim:master Apr 20, 2021
@imagejan
Copy link
Member

imagejan commented Apr 20, 2021

@charismatic-claire when trying to add a regression test doing the round-trip WKT > Bitmask > WKT, I encountered the issue that the behavior of the boundary pixels isn't well-defined (see the javadoc for GeomMasks.polygon2D).

See also the discussion in imagej/imagej-ops#439 and on this forum topic.

Changing the polygon2D() call to closedPolygon2D() solved it for my test case, and should generally be more correct for the use of this plugin, I believe.

Note that I also changed the package of your two new plugins, and renamed the classes, so the KNIME nodes from this repository will differ from what you might have used locally already. This will require some changes to existing KNIME workflows relying on your local version. (I'll take care that future refactoring of this component won't affect the use of these nodes in KNIME, once it got released.)

After cutting a new release version, I'll update the fmi-knime-update-site repository, and the node should be available via KNIME update soon.

@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/polygon-mesh-boundary/3153/10

@charismatic-claire
Copy link
Author

@imagejan I'm glad to hear that. Great!

What you mentioned about the use of the closedPolygon2D() or the polygon2D() method makes total sense to me. If it is the more correct use for the plug-in then that's good. I also thought about that one before but decided not to use it for no particular reason...

Renaming packages and classes and what not is fine too. I'll change my workflows, no problem. So thrilled that this will soon be available via KNIME update.

@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/webinar-introduction-to-knime-for-image-processing-questions-answers/50252/1

@charismatic-claire
Copy link
Author

I think there is a little issue related to this merge and the recently published new version of this plug-in, especially when it comes to running it within KNIME. See here: FMI KNIME Plugins version 0.19.0.202104201635 introduces imglib2 dependency issue #13

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.

3 participants