/** * @param pseudocolor * @return * @throws ALDOperatorException */ public MTBImage create3DTrajectoryImage(boolean pseudocolor) throws ALDOperatorException { MTBImage trajectoryImg; if (pseudocolor) { trajectoryImg = MTBImage.createMTBImage(sizeX, sizeY, sizeT, 1, 1, MTBImage.MTBImageType.MTB_RGB); } else { trajectoryImg = MTBImage.createMTBImage(sizeX, sizeY, sizeT, 1, 1, MTBImage.MTBImageType.MTB_BYTE); } trajectoryImg.fillBlack(); trajectoryImg.setTitle("trajectories"); Random r = new Random(); for (int i = 0; i < trajectories.size(); i++) { Trajectory2D trajectory = trajectories.elementAt(i); int color = trajectory.getID(); if (pseudocolor) { color = r.nextInt((int) Math.pow(2, 32)); } Vector<Point2D.Double> points = trajectory.getPoints(); int startFrame = trajectory.getStartFrame(); for (int j = 0; j < points.size(); j++) { Point2D.Double p = points.elementAt(j); trajectoryImg.putValueInt((int) p.x, (int) p.y, startFrame + j, color); } } return trajectoryImg; }
/** * Creates a <code>MTBImage</code> with three channels, the same size as the original one and * converts each rgb pixel to a <i>hsx</i> pixel, where <i>x</i> stands for Inentsity or * Brightness or Value depending on the mode set. * * <p> * * @throws ALDOperatorException * @throws ALDProcessingDAGException */ @Override protected void operate() throws ALDOperatorException, ALDProcessingDAGException { final MTBImageRGB input = this.getInputMTBImgRGB(); // if input is null -> throw an error if (input == null) { throw new ALDOperatorException( ALDOperatorException.OperatorExceptionType.INSTANTIATION_ERROR, "The input image is null!"); } if (mode == null) { throw new ALDOperatorException( ALDOperatorException.OperatorExceptionType.INSTANTIATION_ERROR, "The operation mode is null!"); } final int width = input.getSizeX(); final int height = input.getSizeY(); // creates a 3-channel image MTBImage.MTBImageType imageType; if (createFloatImage) { imageType = MTBImage.MTBImageType.MTB_FLOAT; } else { imageType = MTBImage.MTBImageType.MTB_BYTE; } resultMTBImg = MTBImage.createMTBImage(width, height, 1, 1, THREE_COMPONENTS_COLOR_SPACE, imageType); // Array of size 3 - containing the r/g/b-values of the actual pixel final int[] rgbColorValues = new int[THREE_COMPONENTS_COLOR_SPACE]; // Array of size 3 - containing the h/s/v-values of the actual pixel float[] hsxColorValues = null; float hueByte, satByte, xByte; // For each Pixel of the input image... for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // rgb-Color : actual Pixel int rgbColorPack = inputMTBImageRGB.getValueInt(x, y); // deflate the color components rgbColorValues[RED_COMPONENT_INDEX] = (rgbColorPack >> 16) & 0xFF; rgbColorValues[GREEN_COMPONENT_INDEX] = (rgbColorPack >> 8) & 0xFF; rgbColorValues[BLUE_COMPONENT_INDEX] = (rgbColorPack) & 0xFF; // conversion from rgb to hsv switch (mode) { case RGB_HSI_SONKA: hsxColorValues = rgbToHSI_Sonka(rgbColorValues); break; case RGB_HSB_JRE: hsxColorValues = rgbToHSB_JRE(rgbColorValues); break; case RGB_HSV_EASY_RGB: hsxColorValues = rgbToHSV_EasyRGB(rgbColorValues); break; default: throw new IllegalArgumentException("The Algorithm : " + mode + " is not supported!"); } // mapping from [0,1] to [0,255] hueByte = hsxColorValues[HUE_COMPONENT_INDEX] * 255F; satByte = hsxColorValues[SATURATION_COMPONENT_INDEX] * 255F; xByte = hsxColorValues[X_COMPONENT_INDEX] * 255F; // set each channel if (createFloatImage) { resultMTBImg.putValueDouble( x, y, 0, 0, HUE_COMPONENT_INDEX, hsxColorValues[HUE_COMPONENT_INDEX]); resultMTBImg.putValueDouble( x, y, 0, 0, SATURATION_COMPONENT_INDEX, hsxColorValues[SATURATION_COMPONENT_INDEX]); resultMTBImg.putValueDouble( x, y, 0, 0, X_COMPONENT_INDEX, hsxColorValues[X_COMPONENT_INDEX]); } else { resultMTBImg.putValueInt( x, y, 0, 0, HUE_COMPONENT_INDEX, Float.valueOf(hueByte).intValue()); resultMTBImg.putValueInt( x, y, 0, 0, SATURATION_COMPONENT_INDEX, Float.valueOf(satByte).intValue()); resultMTBImg.putValueInt(x, y, 0, 0, X_COMPONENT_INDEX, Float.valueOf(xByte).intValue()); } } } // the hue channel is shown by default resultMTBImg.setTitle("HSX image"); // make a copy of each channel final MTBImage tempHueImage = resultMTBImg.getSlice(0, 0, HUE_COMPONENT_INDEX); final MTBImage tempSatImage = resultMTBImg.getSlice(0, 0, SATURATION_COMPONENT_INDEX); final MTBImage tempXImage = resultMTBImg.getSlice(0, 0, X_COMPONENT_INDEX); // label it tempHueImage.setTitle("Hue image"); tempSatImage.setTitle("Saturation image"); final String xChannelName = mode.equals(RGBToHSXConverter.Mode.RGB_HSI_SONKA) ? "Intensity " : mode.equals(RGBToHSXConverter.Mode.RGB_HSB_JRE) ? "Brightness" : "Value "; tempXImage.setTitle(xChannelName + "image"); // set the channel images setHueMTBImg(tempHueImage); setSatMTBImg(tempSatImage); setXMTBImg(tempXImage); }