void drawSpectrum(double h) { Color c; for (int x = 5; x < 7; x++) { for (int y = 0; y < 32; y++) { float hue = (float) (y / (2 * h) - .15); c = Color.getHSBColor(hue, 1f, 1f); setRoi(x * (int) (w / 2), y * (int) (h / 2), (int) w / 2, (int) h / 2); setColor(c); fill(); } } setRoi(55, 32, 22, 16); // Solid red setColor(0xff0000); fill(); setRoi(55, 120, 22, 16); // Solid green setColor(0x00ff00); fill(); setRoi(55, 208, 22, 16); // Solid blue setColor(0x0000ff); fill(); setRoi(55, 80, 22, 8); // Solid yellow setColor(0xffff00); fill(); setRoi(55, 168, 22, 8); // Solid cyan setColor(0x00ffff); fill(); setRoi(55, 248, 22, 8); // Solid magenta setColor(0xff00ff); fill(); }
void drawColors(int colorWidth, int colorHeight, int columns, int rows) { w = colorWidth; h = colorHeight; setColor(0xffffff); setRoi(0, 0, 110, 320); fill(); drawRamp(); resetBW(); flipper(); drawLine(0, 256, 110, 256); int x = 1; int y = 0; refreshBackground(); refreshForeground(); Color c; float hue, saturation = 1f, brightness = 1f; double w = colorWidth, h = colorHeight; for (x = 2; x < 10; x++) { for (y = 0; y < 32; y++) { hue = (float) (y / (2 * h) - .15); if (x < 6) { saturation = 1f; brightness = (float) (x * 4 / w); } else { saturation = 1f - ((float) ((5 - x) * -4 / w)); brightness = 1f; } c = Color.getHSBColor(hue, saturation, brightness); setRoi(x * (int) (w / 2), y * (int) (h / 2), (int) w / 2, (int) h / 2); setColor(c); fill(); } } drawSpectrum(h); resetRoi(); }
ImageProcessor setup(ImagePlus imp) { ImageProcessor ip; int type = imp.getType(); if (type != ImagePlus.COLOR_RGB) return null; ip = imp.getProcessor(); int id = imp.getID(); int slice = imp.getCurrentSlice(); if ((id != previousImageID) | (slice != previousSlice) | (flag)) { flag = false; // if true, flags a change from HSB to RGB or viceversa numSlices = imp.getStackSize(); stack = imp.getStack(); width = stack.getWidth(); height = stack.getHeight(); numPixels = width * height; hSource = new byte[numPixels]; sSource = new byte[numPixels]; bSource = new byte[numPixels]; // restore = (int[])ip.getPixelsCopy(); //This runs into trouble sometimes, so do it the // long way: int[] temp = (int[]) ip.getPixels(); restore = new int[numPixels]; for (int i = 0; i < numPixels; i++) restore[i] = temp[i]; fillMask = new int[numPixels]; // Get hsb or rgb from image. ColorProcessor cp = (ColorProcessor) ip; IJ.showStatus("Gathering data"); if (isRGB) cp.getRGB(hSource, sSource, bSource); else cp.getHSB(hSource, sSource, bSource); IJ.showStatus("done"); // Create a spectrum ColorModel for the Hue histogram plot. Color c; byte[] reds = new byte[256]; byte[] greens = new byte[256]; byte[] blues = new byte[256]; for (int i = 0; i < 256; i++) { c = Color.getHSBColor(i / 255f, 1f, 1f); reds[i] = (byte) c.getRed(); greens[i] = (byte) c.getGreen(); blues[i] = (byte) c.getBlue(); } ColorModel cm = new IndexColorModel(8, 256, reds, greens, blues); // Make an image with just the hue from the RGB image and the spectrum LUT. // This is just for a hue histogram for the plot. Do not show it. // ByteProcessor bpHue = new ByteProcessor(width,height,h,cm); ByteProcessor bpHue = new ByteProcessor(width, height, hSource, cm); ImagePlus impHue = new ImagePlus("Hue", bpHue); // impHue.show(); ByteProcessor bpSat = new ByteProcessor(width, height, sSource, cm); ImagePlus impSat = new ImagePlus("Sat", bpSat); // impSat.show(); ByteProcessor bpBri = new ByteProcessor(width, height, bSource, cm); ImagePlus impBri = new ImagePlus("Bri", bpBri); // impBri.show(); plot.setHistogram(impHue, 0); splot.setHistogram(impSat, 1); bplot.setHistogram(impBri, 2); updateLabels(); updatePlot(); updateScrollBars(); imp.updateAndDraw(); } previousImageID = id; previousSlice = slice; return ip; }