fiji / Trainable_Segmentation

Fiji library to perform image segmentation based on the Weka learning schemes
https://imagej.net/Trainable_Weka_Segmentation
GNU General Public License v3.0
106 stars 60 forks source link

Question about Opacity #46

Open nkoutroumanis opened 6 years ago

nkoutroumanis commented 6 years ago

How can i create result of an image with 50% opacity through Java?

ctrueden commented 6 years ago

@nkoutroumanis The java.awt.image API lets you create BufferedImage objects with alpha channel. See e.g. this SO post. But that is not really specific to Trainable Weka Segmentation or ImageJ. Are you asking how to make TWS spit out an image at a different opacity? The short answer is: you can't, but you can paint the TWS output image onto a BufferedImage at 50% opacity as described in the link.

imagejan commented 6 years ago

If you have an ImageRoi, you can set the opacity using setOpacity(double opacity).

For area ROIs (that can be filled), you can use an Overlay, as illustrated by this Groovy script:

#@ ImagePlus imp
#@ Integer (min=0, max=255) alpha

import java.awt.Color
import ij.gui.Overlay

roi = imp.getRoi()

ovl = new Overlay(roi)
ovl.setFillColor(new Color(255,0,0,alpha))

imp.setOverlay(ovl)