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

Feature Request: Keep/Remove Largest Region in 2D for stacks #53

Open
agclark12 opened this issue Apr 29, 2021 · 5 comments
Open

Feature Request: Keep/Remove Largest Region in 2D for stacks #53

agclark12 opened this issue Apr 29, 2021 · 5 comments

Comments

@agclark12
Copy link

I often deal with stacks of time series data, where I am segmenting and cleaning segmentations for each frame sequentially. If I would like to keep or remove a largest region for each slice, MorphoLibJ automatically does the labeling in 3D. It would be nice if one could choose to do this in 2D slice-by-slice for a timeseries. That would save a lot of work having to go through the stack and pull out individual frames to do this. Thanks!

@dlegland
Copy link
Contributor

Hi,

Yes, the library currently uses the connectivity withj dimension corresponding to that of the input image.
I am not a big fan of providing too much choices for "low-level" operators; the design strategy is rather to build workflows / encapsulate into macros or more general plugins. Maybe you can build such a macro?

Anyway, a trick could be to allow 2D connectivities for 3D arrays. Regions in consecutive slices/frames would therefore have distinct labels. We can think about it.

@agclark12
Copy link
Author

Sure. I understand. I already have already written macros that do this for my work flows. I was just thinking about this while putting together a new work flow since there doesn't seem to be an easy way to do this for a time series aside from using a macro. I thought the output from a timeseries may be somewhat confusing for someone who is not so familiar with connected component analysis.

Maybe it could at least be included in the documentation that the image dimensionality is used for determining the connectivity. Otherwise, as you mention, an option to use 2D connectivity for 3D arrays would be a nice solution. Or, if the stack is a time series, it could use 2D connectivity, while if it is a z-series it could use 3D. I think that might make sense in terms of what people want out of this function considering their input data. Although, as one sometimes loses track of whether their slices are considered time or z-slices, it could also be confusing. I guess there is probably not an ideal solution for all users. Anyway, thanks! I use this package a lot!

@iarganda
Copy link
Contributor

I actually wrote some scripts to do that and I also wonder if it would be worth it for some plugins to include the "Apply to stack" option in 2D as in regular 2D filters in ImageJ...

@dlegland
Copy link
Contributor

Hmm, yes, for 2D processing, we could envision adding such an option! We can also add the option only in the case of a 3D input image.

@agclark12
Copy link
Author

Having such a standard "Apply to Stack" option would also make the scripting much easier because you can just iterate through the stack and run it on each slice instead of having to pull out slices one by one and make a new output stack. For anyone who stumbles on this thread and needs a way to do this in the macro, here is a small example to make this work for a stack where you only want 2D connectivity for each slice (e.g. time series):

//makes a new image with same dimensions as the original
rename("stk");
getDimensions(width, height, channels, slices, frames);
newImage("new", "8-bit", width, height, slices);

//cleans up segmentation for each frame
for (i=1;i<slices+1;i++) {

	selectWindow("stk");
	setSlice(i);
	run("Duplicate...", " ");
	rename("curr");
	run("Keep Largest Region");
	run("Fill Holes", "");
	run("Select All");
	run("Copy");
	selectWindow("new");
	setSlice(i);
	run("Paste");
	run("Select None");
	close("curr");
	close("curr-largest");
	
}

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

No branches or pull requests

3 participants