use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class ROIMultiPaintManager method duplicateROIData.
private void duplicateROIData(final int newZSize) {
final AsynchClientTask extrudeTask = new AsynchClientTask("Extruding...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
ISize origSize = getImageDataSetChannel().getISize();
if (origSize.getZ() != 1 || newZSize < 1) {
throw new IllegalArgumentException("Extrude assumes starting with 2D and new Z size >= 1.");
}
UShortImage[][] newUnderLayImageArr = new UShortImage[initImageDataSetChannels.length][newZSize];
BufferedImage[] newROICompositeArr = new BufferedImage[newZSize];
for (int i = 0; i < newZSize; i++) {
for (int c = 0; c < initImageDataSetChannels.length; c++) {
// short[] zslice = new short[initImageDataSetChannels[c].getAllImages()[0].getPixels().length];
// System.arraycopy(initImageDataSetChannels[c].getAllImages()[0].getPixels(), 0, zslice, 0, zslice.length);
newUnderLayImageArr[c][i] = new UShortImage(// zslice,
initImageDataSetChannels[c].getAllImages()[0].getPixels().clone(), DEFAULT_ORIGIN, DEFAULT_EXTENT, initImageDataSetChannels[c].getAllImages()[0].getNumX(), initImageDataSetChannels[c].getAllImages()[0].getNumY(), 1);
}
newROICompositeArr[i] = new BufferedImage(roiComposite[0].getWidth(), roiComposite[0].getHeight(), BufferedImage.TYPE_BYTE_INDEXED, getContrastIndexColorModel());
System.arraycopy((byte[]) ((DataBufferByte) roiComposite[0].getRaster().getDataBuffer()).getData(), 0, (byte[]) ((DataBufferByte) newROICompositeArr[i].getRaster().getDataBuffer()).getData(), 0, origSize.getX() * origSize.getY());
}
for (int c = 0; c < initImageDataSetChannels.length; c++) {
initImageDataSetChannels[c] = new ImageDataset(newUnderLayImageArr[c], null, newZSize);
}
roiComposite = newROICompositeArr;
if (!(enhanceImageAmount == ROIMultiPaintManager.ENHANCE_NONE)) {
getClientTaskStatusSupport().setMessage("smoothing...");
}
updateAuxiliaryInfo(origSize, getClientTaskStatusSupport());
}
};
final AsynchClientTask updatePanelTask = getUpdateDisplayAfterCropTask();
ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<String, Object>(), new AsynchClientTask[] { extrudeTask, updatePanelTask }, false, false, null, true);
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class OverlayEditorPanelJAI method displaySpecialData.
public void displaySpecialData(short[] specialData, int width, int height) throws Exception {
if (specialData == null) {
forceImage();
return;
}
UShortImage specialUShortImage = new UShortImage(specialData, null, null, width, height, 1);
BufferedImage specialBufferedImage = createUnderlyingImage(specialUShortImage);
imagePane.setUnderlyingImage(specialBufferedImage, /* false,*/
null);
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class VFrap_OverlayEditorPanelJAI method getImportROIMaskButton.
public JButton getImportROIMaskButton() {
if (importROIMaskButton == null) {
importROIMaskButton = new JButton(new ImageIcon(getClass().getResource("/images/importROI.gif")));
importROIMaskButton.setPreferredSize(new Dimension(32, 32));
importROIMaskButton.setMargin(new Insets(2, 2, 2, 2));
importROIMaskButton.setToolTipText("Import ROI mask from file");
importROIMaskButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
File inputFile = null;
try {
int option = openJFileChooser.showOpenDialog(VFrap_OverlayEditorPanelJAI.this);
if (option == JFileChooser.APPROVE_OPTION) {
inputFile = openJFileChooser.getSelectedFile();
} else {
throw UserCancelException.CANCEL_GENERIC;
}
if (!customROIImport.importROI(inputFile)) {
ImageDataset importImageDataset = ImageDatasetReaderService.getInstance().getImageDatasetReader().readImageDataset(inputFile.getAbsolutePath(), null);
if (importImageDataset.getISize().getX() * importImageDataset.getISize().getY() != getImagePane().getHighlightImage().getWidth() * getImagePane().getHighlightImage().getHeight()) {
throw new Exception("Imported ROI mask size (" + importImageDataset.getISize().getX() + "," + importImageDataset.getISize().getY() + ")" + " does not match current Frap DataSet size (" + getImagePane().getHighlightImage().getWidth() + "," + getImagePane().getHighlightImage().getHeight() + ")");
}
// BufferedImage roiMaskImage = BufferedImageReader.makeBufferedImageReader(iFormatReader).openImage(0);
UShortImage roiMaskImage = importImageDataset.getImage(0, 0, 0);
int maskColor = highlightColor.getRGB();
for (int y = 0; y < importImageDataset.getISize().getY(); y++) {
for (int x = 0; x < importImageDataset.getISize().getX(); x++) {
if ((roiMaskImage.getPixel(x, y, 0) & 0xFFFF) != 0) {
getImagePane().getHighlightImage().setRGB(x, y, maskColor);
}
}
}
getImagePane().refreshImage();
}
} catch (UserCancelException uce) {
// Do Nothing
} catch (Exception e1) {
e1.printStackTrace();
DialogUtils.showErrorDialog(VFrap_OverlayEditorPanelJAI.this, "Error importing ROI" + e1.getMessage());
}
}
});
}
return importROIMaskButton;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class VFrap_OverlayEditorPanelJAI method createHighlightImageFromROI.
/**
* Method createHighlightImageFromROI.
* @return BufferedImage
*/
private BufferedImage createHighlightImageFromROI() {
int[] cmap = new int[256];
// colormap (grayscale)
for (int i = 0; i < 256; i += 1) {
if (i != 0) {
cmap[i] = 0xFF000000 | highlightColor.getRGB();
} else {
cmap[1] = 0xFF000000;
}
}
IndexColorModel indexColorModel = new java.awt.image.IndexColorModel(8, cmap.length, cmap, 0, false, /*false means NOT USE alpha*/
-1, /*NO transparent single pixel*/
java.awt.image.DataBuffer.TYPE_BYTE);
UShortImage roiImage = roi.getRoiImages()[getRoiImageIndex()];
int width = roiImage.getNumX();
int height = roiImage.getNumY();
BufferedImage hiLiteImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, indexColorModel);
byte[] hiLiteArr = ((DataBufferByte) hiLiteImage.getRaster().getDataBuffer()).getData();
for (int i = 0; i < roiImage.getPixels().length; i++) {
hiLiteArr[i] = (roiImage.getPixels()[i] != 0 ? (byte) highlightColor.getRed() : 0);
}
return hiLiteImage;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class VFrap_OverlayEditorPanelJAI method calcMinMaxPixelValueRange.
private Range calcMinMaxPixelValueRange(ImageDataset argImageDataset) {
UShortImage[] allImages = argImageDataset.getAllImages();
double min = 0;
double max = min;
for (int i = 0; i < allImages.length; i++) {
ImageStatistics imageStats = allImages[i].getImageStatistics();
if (i == 0 || imageStats.minValue < min) {
min = imageStats.minValue;
}
if (i == 0 || imageStats.maxValue > max) {
max = imageStats.maxValue;
}
}
if (max < SHORT_TO_BYTE_FACTOR) {
return new Range(min, max);
}
return new Range(min / SHORT_TO_BYTE_FACTOR, max / SHORT_TO_BYTE_FACTOR);
}
Aggregations