use of java.awt.Color in project GDSC-SMLM by aherbert.
the class DrawClusters method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "No localisations in memory");
return;
}
if (!showDialog())
return;
// Load the results
MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, false);
if (results == null || results.size() == 0) {
IJ.error(TITLE, "No results could be loaded");
return;
}
// Get the traces
Trace[] traces = TraceManager.convert(results);
if (traces == null || traces.length == 0) {
IJ.error(TITLE, "No traces could be loaded");
return;
}
// Filter traces to a min size
int maxFrame = 0;
int count = 0;
final int myMaxSize = (maxSize < minSize) ? Integer.MAX_VALUE : maxSize;
final boolean myDrawLines = (myMaxSize < 2) ? false : drawLines;
for (int i = 0; i < traces.length; i++) {
if (expandToSingles)
traces[i].expandToSingles();
if (traces[i].size() >= minSize && traces[i].size() <= myMaxSize) {
traces[count++] = traces[i];
traces[i].sort();
if (maxFrame < traces[i].getTail().getFrame())
maxFrame = traces[i].getTail().getFrame();
}
}
if (count == 0) {
IJ.error(TITLE, "No traces achieved the size limits");
return;
}
String msg = String.format(TITLE + ": %d / %s (%s)", count, Utils.pleural(traces.length, "trace"), Utils.pleural(results.size(), "localisation"));
IJ.showStatus(msg);
//Utils.log(msg);
Rectangle bounds = results.getBounds(true);
ImagePlus imp = WindowManager.getImage(title);
boolean isUseStackPosition = useStackPosition;
if (imp == null) {
// Create a default image using 100 pixels as the longest edge
double maxD = (bounds.width > bounds.height) ? bounds.width : bounds.height;
int w, h;
if (maxD == 0) {
// Note that imageSize can be zero (for auto sizing)
w = h = (imageSize == 0) ? 20 : imageSize;
} else {
// Note that imageSize can be zero (for auto sizing)
if (imageSize == 0) {
w = bounds.width;
h = bounds.height;
} else {
w = (int) (imageSize * bounds.width / maxD);
h = (int) (imageSize * bounds.height / maxD);
}
}
ByteProcessor bp = new ByteProcessor(w, h);
if (isUseStackPosition) {
ImageStack stack = new ImageStack(w, h, maxFrame);
for (int i = 1; i <= maxFrame; i++) // Do not clone as the image is empty
stack.setPixels(bp.getPixels(), i);
imp = Utils.display(TITLE, stack);
} else
imp = Utils.display(TITLE, bp);
// Enlarge
ImageWindow iw = imp.getWindow();
for (int i = 9; i-- > 0 && iw.getWidth() < 500 && iw.getHeight() < 500; ) {
iw.getCanvas().zoomIn(imp.getWidth() / 2, imp.getHeight() / 2);
}
} else {
// Check if the image has enough frames for all the traces
if (maxFrame > imp.getNFrames())
isUseStackPosition = false;
}
final float xScale = (float) (imp.getWidth() / bounds.getWidth());
final float yScale = (float) (imp.getHeight() / bounds.getHeight());
// Create ROIs and store data to sort them
Roi[] rois = new Roi[count];
int[][] frames = (isUseStackPosition) ? new int[count][] : null;
int[] indices = Utils.newArray(count, 0, 1);
double[] values = new double[count];
for (int i = 0; i < count; i++) {
Trace trace = traces[i];
int nPoints = trace.size();
float[] xPoints = new float[nPoints];
float[] yPoints = new float[nPoints];
int j = 0;
if (isUseStackPosition)
frames[i] = new int[nPoints];
for (PeakResult result : trace.getPoints()) {
xPoints[j] = (result.getXPosition() - bounds.x) * xScale;
yPoints[j] = (result.getYPosition() - bounds.y) * yScale;
if (isUseStackPosition)
frames[i][j] = result.getFrame();
j++;
}
Roi roi;
if (myDrawLines) {
roi = new PolygonRoi(xPoints, yPoints, nPoints, Roi.POLYLINE);
if (splineFit)
((PolygonRoi) roi).fitSpline();
} else {
roi = new PointRoi(xPoints, yPoints, nPoints);
((PointRoi) roi).setShowLabels(false);
}
rois[i] = roi;
switch(sort) {
case 0:
default:
break;
case // Sort by ID
1:
values[i] = traces[i].getId();
break;
case // Sort by time
2:
values[i] = traces[i].getHead().getFrame();
break;
case // Sort by size descending
3:
values[i] = -traces[i].size();
break;
case // Sort by length descending
4:
values[i] = -roi.getLength();
break;
case // Mean Square Displacement
5:
values[i] = -traces[i].getMSD();
break;
case // Mean / Frame
6:
values[i] = -traces[i].getMeanPerFrame();
break;
}
}
if (sort > 0)
Sort.sort(indices, values);
// Draw the traces as ROIs on an overlay
Overlay o = new Overlay();
LUT lut = LUTHelper.createLUT(DrawClusters.lut);
final double scale = 256.0 / count;
if (isUseStackPosition) {
// Add the tracks on the frames containing the results
final boolean isHyperStack = imp.isDisplayedHyperStack();
for (int i = 0; i < count; i++) {
final int index = indices[i];
final Color c = LUTHelper.getColour(lut, (int) (i * scale));
final PolygonRoi roi = (PolygonRoi) rois[index];
roi.setFillColor(c);
roi.setStrokeColor(c);
final FloatPolygon fp = roi.getNonSplineFloatPolygon();
// For each frame in the track, add the ROI track and a point ROI for the current position
for (int j = 0; j < frames[index].length; j++) {
addToOverlay(o, (Roi) roi.clone(), isHyperStack, frames[index][j]);
//PointRoi pointRoi = new PointRoi(pos.x + fp.xpoints[j], pos.y + fp.ypoints[j]);
PointRoi pointRoi = new PointRoi(fp.xpoints[j], fp.ypoints[j]);
pointRoi.setPointType(3);
pointRoi.setFillColor(c);
pointRoi.setStrokeColor(Color.black);
addToOverlay(o, pointRoi, isHyperStack, frames[index][j]);
}
}
} else {
// Add the tracks as a single overlay
for (int i = 0; i < count; i++) {
final Roi roi = rois[indices[i]];
roi.setStrokeColor(new Color(lut.getRGB((int) (i * scale))));
o.add(roi);
}
}
imp.setOverlay(o);
IJ.showStatus(msg);
}
use of java.awt.Color in project GDSC-SMLM by aherbert.
the class DriftCalculator method plotDrift.
private PlotWindow plotDrift(PlotWindow src, PlotWindow parent, double[][] interpolated, double[][] original, String name, int index) {
// Create plot
double[] a = Maths.limits(interpolated[0]);
double[] b = Maths.limits(original[index]);
b = Maths.limits(b, interpolated[index]);
Plot2 plot = new Plot2(name, "Frame", "Drift (px)", (float[]) null, (float[]) null);
plot.setLimits(a[0], a[1], b[0], b[1]);
// De-saturated blue
plot.setColor(new Color(0, 0, 155));
plot.addPoints(original[0], original[index], Plot2.CROSS);
plot.setColor(java.awt.Color.RED);
plot.addPoints(interpolated[0], interpolated[index], Plot2.LINE);
src = Utils.display(name, plot);
if (Utils.isNewWindow() && parent != null) {
Point location = parent.getLocation();
location.y += parent.getHeight();
src.setLocation(location);
}
return src;
}
use of java.awt.Color in project adempiere by adempiere.
the class MPrintColor method getRRGGBB.
// setColor
/**
* Get Color as RRGGBB hex string for HTML font tag
* @return rgb hex value
*/
public String getRRGGBB() {
Color color = getColor();
StringBuffer sb = new StringBuffer();
sb.append(Util.toHex((byte) color.getRed())).append(Util.toHex((byte) color.getGreen())).append(Util.toHex((byte) color.getBlue()));
return sb.toString();
}
use of java.awt.Color in project adempiere by adempiere.
the class MPrintColor method main.
// toString
/**************************************************************************
* Create Standard Colors
* @param args args
*/
public static void main(String[] args) {
org.compiere.Adempiere.startupEnvironment(true);
Color[] colors = new Color[] { Color.black, Color.red, Color.green, Color.blue, Color.darkGray, Color.gray, Color.lightGray, Color.white, Color.cyan, Color.magenta, Color.orange, Color.pink, Color.yellow, SystemColor.textHighlight };
String[] names = new String[] { "Black", "Red", "Green", "Blue", "Gray dark", "Gray", "Gray light", "White", "Cyan", "Magenta", "Orange", "Pink", "Yellow", "Blue dark" };
for (int i = 0; i < colors.length; i++) System.out.println(names[i] + " = " + colors[i] + " RGB=" + colors[i].getRGB() + " -> " + new Color(colors[i].getRGB(), false) + " -> " + new Color(colors[i].getRGB(), true));
/**
// Create Colors
for (int i = 0; i < colors.length; i++)
create(colors[i], names[i]);
create(whiteGray, "Gray white");
create(darkGreen, "Green dark");
create(blackGreen, "Green black");
create(blackBlue, "Blue black");
create(brown, "Brown");
create(darkBrown, "Brown dark");
**/
// Read All Colors
int[] IDs = PO.getAllIDs("AD_PrintColor", null, null);
for (int i = 0; i < IDs.length; i++) {
MPrintColor pc = new MPrintColor(Env.getCtx(), IDs[i], null);
System.out.println(IDs[i] + ": " + pc + " = " + pc.getColor() + ", RGB=" + pc.getColor().getRGB());
}
}
use of java.awt.Color in project GDSC-SMLM by aherbert.
the class CreateData method showSimpleDialog.
/**
* Show a dialog allowing the parameters for a simple/benchmark simulation to be performed
*
* @return True if the parameters were collected
*/
private boolean showSimpleDialog() {
GenericDialog gd = new GenericDialog(TITLE);
globalSettings = SettingsManager.loadSettings();
settings = globalSettings.getCreateDataSettings();
// Image size
gd.addMessage("--- Image Size ---");
gd.addNumericField("Pixel_pitch (nm)", settings.pixelPitch, 2);
gd.addNumericField("Size (px)", settings.size, 0);
if (!benchmarkMode) {
gd.addNumericField("Depth (nm)", settings.depth, 0);
gd.addCheckbox("Fixed_depth", settings.fixedDepth);
}
// Noise model
gd.addMessage("--- Noise Model ---");
if (extraOptions)
gd.addCheckbox("No_poisson_noise", !settings.poissonNoise);
gd.addNumericField("Background (photons)", settings.background, 2);
gd.addNumericField("EM_gain", settings.getEmGain(), 2);
gd.addNumericField("Camera_gain (ADU/e-)", settings.getCameraGain(), 4);
gd.addNumericField("Quantum_efficiency", settings.getQuantumEfficiency(), 2);
gd.addNumericField("Read_noise (e-)", settings.readNoise, 2);
gd.addNumericField("Bias", settings.bias, 0);
// PSF Model
List<String> imageNames = addPSFOptions(gd);
gd.addMessage("--- Fluorophores ---");
Component splitLabel = gd.getMessage();
// Do not allow grid or mask distribution
if (simpleMode) {
// Allow mask but not the grid
gd.addChoice("Distribution", Arrays.copyOf(DISTRIBUTION, DISTRIBUTION.length - 1), settings.distribution);
gd.addCheckbox("Sample_per_frame", settings.samplePerFrame);
}
gd.addNumericField("Particles", settings.particles, 0);
if (simpleMode)
gd.addNumericField("Density (um^-2)", settings.density, 2);
else if (benchmarkMode) {
gd.addNumericField("X_position (nm)", settings.xPosition, 2);
gd.addNumericField("Y_position (nm)", settings.yPosition, 2);
gd.addNumericField("Z_position (nm)", settings.zPosition, 2);
}
gd.addNumericField("Min_Photons", settings.photonsPerSecond, 0);
gd.addNumericField("Max_Photons", settings.photonsPerSecondMaximum, 0);
gd.addMessage("--- Save options ---");
gd.addCheckbox("Raw_image", settings.rawImage);
gd.addCheckbox("Save_image", settings.saveImage);
gd.addCheckbox("Save_image_results", settings.saveImageResults);
gd.addCheckbox("Save_localisations", settings.saveLocalisations);
gd.addMessage("--- Report options ---");
gd.addCheckbox("Show_histograms", settings.showHistograms);
gd.addCheckbox("Choose_histograms", settings.chooseHistograms);
gd.addNumericField("Histogram_bins", settings.histogramBins, 0);
gd.addCheckbox("Remove_outliers", settings.removeOutliers);
if (simpleMode)
gd.addSlider("Density_radius (N x HWHM)", 0, 4.5, settings.densityRadius);
gd.addNumericField("Depth-of-field (nm)", settings.depthOfField, 0);
if (gd.getLayout() != null) {
GridBagLayout grid = (GridBagLayout) gd.getLayout();
int xOffset = 0, yOffset = 0;
int lastY = -1, rowCount = 0;
for (Component comp : gd.getComponents()) {
// Check if this should be the second major column
if (comp == splitLabel) {
xOffset += 2;
yOffset -= rowCount;
rowCount = 0;
}
// Reposition the field
GridBagConstraints c = grid.getConstraints(comp);
if (lastY != c.gridy)
rowCount++;
lastY = c.gridy;
c.gridx = c.gridx + xOffset;
c.gridy = c.gridy + yOffset;
c.insets.left = c.insets.left + 10 * xOffset;
c.insets.top = 0;
c.insets.bottom = 0;
grid.setConstraints(comp, c);
}
if (IJ.isLinux())
gd.setBackground(new Color(238, 238, 238));
}
gd.showDialog();
if (gd.wasCanceled())
return false;
settings.pixelPitch = Math.abs(gd.getNextNumber());
settings.size = Math.abs((int) gd.getNextNumber());
if (!benchmarkMode) {
// Allow negative depth
settings.depth = gd.getNextNumber();
settings.fixedDepth = gd.getNextBoolean();
}
if (extraOptions)
poissonNoise = settings.poissonNoise = !gd.getNextBoolean();
settings.background = Math.abs(gd.getNextNumber());
settings.setEmGain(Math.abs(gd.getNextNumber()));
settings.setCameraGain(Math.abs(gd.getNextNumber()));
settings.setQuantumEfficiency(Math.abs(gd.getNextNumber()));
settings.readNoise = Math.abs(gd.getNextNumber());
settings.bias = Math.abs((int) gd.getNextNumber());
if (!collectPSFOptions(gd, imageNames))
return false;
if (simpleMode) {
settings.distribution = gd.getNextChoice();
settings.samplePerFrame = gd.getNextBoolean();
}
settings.particles = Math.abs((int) gd.getNextNumber());
if (simpleMode)
settings.density = Math.abs(gd.getNextNumber());
else if (benchmarkMode) {
settings.xPosition = gd.getNextNumber();
settings.yPosition = gd.getNextNumber();
settings.zPosition = gd.getNextNumber();
}
settings.photonsPerSecond = Math.abs((int) gd.getNextNumber());
settings.photonsPerSecondMaximum = Math.abs((int) gd.getNextNumber());
settings.rawImage = gd.getNextBoolean();
settings.saveImage = gd.getNextBoolean();
settings.saveImageResults = gd.getNextBoolean();
settings.saveLocalisations = gd.getNextBoolean();
settings.showHistograms = gd.getNextBoolean();
settings.chooseHistograms = gd.getNextBoolean();
settings.histogramBins = (int) Math.abs(gd.getNextNumber());
settings.removeOutliers = gd.getNextBoolean();
if (simpleMode)
settings.densityRadius = (float) gd.getNextNumber();
settings.depthOfField = (float) Math.abs(gd.getNextNumber());
// Save before validation so that the current values are preserved.
SettingsManager.saveSettings(globalSettings);
if (gd.invalidNumber())
return false;
// Check arguments
try {
Parameters.isAboveZero("Pixel Pitch", settings.pixelPitch);
Parameters.isAboveZero("Size", settings.size);
if (!benchmarkMode && !settings.fixedDepth)
Parameters.isPositive("Depth", settings.depth);
Parameters.isPositive("Background", settings.background);
Parameters.isPositive("EM gain", settings.getEmGain());
Parameters.isPositive("Camera gain", settings.getCameraGain());
Parameters.isPositive("Read noise", settings.readNoise);
double noiseRange = settings.readNoise * settings.getCameraGain() * 4;
Parameters.isEqualOrAbove("Bias must prevent clipping the read noise (@ +/- 4 StdDev) so ", settings.bias, noiseRange);
Parameters.isAboveZero("Particles", settings.particles);
if (simpleMode)
Parameters.isAboveZero("Density", settings.density);
Parameters.isAboveZero("Min Photons", settings.photonsPerSecond);
if (settings.photonsPerSecondMaximum < settings.photonsPerSecond)
settings.photonsPerSecondMaximum = settings.photonsPerSecond;
if (!imagePSF) {
Parameters.isAboveZero("Wavelength", settings.wavelength);
Parameters.isAboveZero("NA", settings.numericalAperture);
Parameters.isBelow("NA", settings.numericalAperture, 2);
}
Parameters.isPositive("Histogram bins", settings.histogramBins);
if (simpleMode)
Parameters.isPositive("Density radius", settings.densityRadius);
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return false;
}
if (settings.distribution.equals(DISTRIBUTION[MASK])) {
String[] maskImages = createDistributionImageList();
if (maskImages != null) {
gd = new GenericDialog(TITLE);
gd.addMessage("Select the mask image for the distribution");
gd.addChoice("Distribution_mask", maskImages, settings.distributionMask);
if (maskListContainsStacks)
gd.addNumericField("Distribution_slice_depth (nm)", settings.distributionMaskSliceDepth, 0);
gd.showDialog();
if (gd.wasCanceled())
return false;
settings.distributionMask = gd.getNextChoice();
if (maskListContainsStacks)
settings.distributionMaskSliceDepth = Math.abs(gd.getNextNumber());
}
SettingsManager.saveSettings(globalSettings);
}
return getHistogramOptions();
}
Aggregations