Comments (1)
Ok, got it. It's quite simple:
import imagej, scyjava
scyjava.config.add_option('-Xmx6g')
ij = imagej.init(mode='interactive')
imp = ij.IJ.openImage('INPUT_IMAGE.tiff')
imp2 = imp.duplicate()
ip = imp2.getProcessor()
width = imp2.getWidth()
height = imp2.getHeight() - 1
RM = ij.RoiManager() # we create an instance of the RoiManager class
rm = RM.getRoiManager() # "activate" the RoiManager otherwise it can behave strangely
max_label = int(imp2.getStatistics().max)
max_digits = int(math.ceil(math.log(max_label,10))) # Calculate the number of digits for the name of the ROI (padding with zeros)
ij.IJ.setForegroundColor(0, 0, 0) # We pick black color to delete the label already computed
roiID = -1
# Iterate over picture and identify pixel values
for j in range(height):
for i in range(width):
current_pixel_value = ip.getValue(i,j)
if current_pixel_value > 0:
roiID +=1
# Select all pixels with same value in image
ij.IJ.doWand(imp2, i, j, 0.0, "Legacy smooth");
# Add as ROI to the ROI manager
roi = imp2.getRoi()
# Set roiname to roiID_X_Y (center_point).
roi.setName(str(roiID) + "_" + #str(int(current_pixel_value)).zfill(max_digits)) # Old
str(round(roi.getXBase() + roi.getFloatWidth()/2)) + "_" +
str(round(roi.getYBase() + roi.getFloatHeight()/2)))
rm.addRoi(roi) #Error.. Static method was being called without being instantiated
# Fill inner part of roi with 0s so it becomes an outline
ip.setColor(0); # Fix 32 bit issue
ip.fill(roi) # Much faster than IJ.run(imp2, "Fill", ....
rm.save("outputDIR/tmp.zip")
from labelstorois.
Related Issues (13)
- Error loading plugin HOT 6
- File selectionJFileChooser MacOS issues
- generated measurements table HOT 3
- java error IOException: Mark invalid
- Crashes with 32-bit label image HOT 1
- Error loading plugin HOT 2
- only save outlines/overlay as skeleton? HOT 1
- Error when reading multiple images HOT 1
- UPDATE! numerous issues solved
- Fiji crashes HOT 2
- exclude cells on edges HOT 2
- remove small lables HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from labelstorois.