本文整理了Java中ij.gui.Overlay
类的一些代码示例,展示了Overlay
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Overlay
类的具体详情如下:
包路径:ij.gui.Overlay
类名称:Overlay
[英]An Overlay is a list of ROIs that can be drawn non-destructively on an Image.
[中]覆盖是可以在图像上以非破坏性方式绘制的ROI列表。
代码示例来源:origin: stackoverflow.com
import java.io.File;
import java.util.HashMap;
import org.apache.pdfbox.multipdf.Overlay;
import org.apache.pdfbox.pdmodel.PDDocument;
public class TestPDF {
public static void main(String[] args) throws Exception{
PDDocument realDoc = PDDocument.load(new File("originaldocument.pdf"));
//the above is the document you want to watermark
//for all the pages, you can add overlay guide, indicating watermark the original pages with the watermark document.
HashMap<Integer, String> overlayGuide = new HashMap<Integer, String>();
for(int i=0; i<realDoc.getNumberOfPages(); i++){
overlayGuide.put(i+1, "watermark.pdf");
//watermark.pdf is the document which is a one page PDF with your watermark image in it.
//Notice here, you can skip pages from being watermarked.
}
Overlay overlay = new Overlay();
overlay.setInputPDF(realDoc);
overlay.setOutputFile("final.pdf");
overlay.setOverlayPosition(Overlay.Position.BACKGROUND);
overlay.overlay(overlayGuide);
}
}
代码示例来源:origin: stackoverflow.com
PDDocument watermarkDoc = PDDocument.load("watermark.pdf");
//Assuming your empty document with watermark image in it.
PDDocument realDoc = PDDocument.load("document-to-be-watermarked.pdf");
//Let's say this is your document that you want to watermark. For example sake, I am opening a new one, you would already have a reference to PDDocument if you are creating one
Overlay overlay = new Overlay();
overlay.overlay(realDoc,watermarkDoc);
watermarkDoc.save("document-now-watermarked.pdf");
代码示例来源:origin: net.imagej/ij
ImageStack stack2 = new ImageStack(newWidth, newHeight);
boolean virtualStack = stack1.isVirtual();
method = ImageProcessor.NONE;
for (int i=1; i<=nSlices; i++) {
IJ.showStatus("Scale: " + i + "/" + nSlices);
ip1 = stack1.getProcessor(i);
ip1.setRoi(r);
ip1 = ip1.crop();
IJ.showProgress(i, nSlices);
overlay = null;
if (overlay!=null) {
overlay = overlay.duplicate();
Overlay overlay2 = new Overlay();
for (int i=0; i<overlay.size(); i++) {
Roi roi = overlay.get(i);
Rectangle bounds = roi.getBounds();
if (roi instanceof ImageRoi && bounds.x==0 && bounds.y==0) {
ImageRoi iroi = (ImageRoi)roi;
overlay2.add(iroi);
if (overlay2.size()>0)
IJ.showProgress(1.0);
代码示例来源:origin: net.imagej/ij
public void convertStackToImages(ImagePlus imp) {
if (nSlices<2) {
IJ.wait(500);
imp = IJ.getImage();
nSlices = imp.getStackSize();
IJ.error("\"Convert Stack to Images\" requires a stack\n"+imp);
return;
if (!imp.lock())
return;
ImageStack stack = imp.getStack();
int size = stack.getSize();
Overlay overlay2 = new Overlay();
for (int j=0; j<overlay.size(); j++) {
Roi roi = overlay.get(j);
if (roi.getPosition()==i) {
roi.setPosition(0);
overlay2.add((Roi)roi.clone());
if (overlay2.size()>0)
代码示例来源:origin: net.imagej/ij
impB.deleteRoi(); //we have it in roiA
Color colorBack = Toolbar.getBackgroundColor();
IJ.setBackgroundColor(0,0,0);
String title = impB.getTitle();
if(impB.getOverlay() != null)
impB.getOverlay().clear();
int boundLeft = roiA.getBounds().x;
int boundTop = roiA.getBounds().y;
int boundWidth = roiA.getBounds().width;
int boundHeight = roiA.getBounds().height;
impB.setStack(stackNew);
ImageProcessor ip = impB.getProcessor();
ip.setInterpolationMethod(ImageProcessor.BILINEAR);
ip.setBackgroundValue(0);
for (int slc = 0; slc < stackNew.size(); slc++) {
impB.setSlice(slc+1);
ip.rotate(phi0); //Rotate
ip.translate(dx4, dy4); //Translate
int y = (impB.getHeight() - (int) rrHeight) / 2;
impB.setStack(impB.getStack().crop(x, y, 0, (int) rrWidth, (int) rrHeight, impB.getStack().getSize()));//Crop
impB.setSlice(currentSlice);
impB.setTitle(title);
代码示例来源:origin: net.imagej/ij
private ImagePlus convert(ImagePlus[] images, int count) {
double min = Double.MAX_VALUE;
double max = -Double.MAX_VALUE;
ImageStack stack = new ImageStack(width, height);
FileInfo fi = images[0].getOriginalFileInfo();
if (fi!=null && fi.directory==null) fi = null;
Overlay overlay = new Overlay();
for (int i=0; i<count; i++) {
ImageProcessor ip = images[i].getProcessor();
boolean invertedLut = ip.isInvertedLut();
if (ip.getMin()<min) min = ip.getMin();
if (ip.getMax()>max) max = ip.getMax();
String label = titlesAsLabels?images[i].getTitle():null;
if (label!=null) {
String info = (String)images[i].getProperty("Info");
Overlay overlay2 = images[i].getOverlay();
if (overlay2!=null) {
for (int j=0; j<overlay2.size(); j++) {
Roi roi = overlay2.get(j);
roi.setPosition(i+1);
overlay.add((Roi)roi.clone());
imp.setFileInfo(fi);
if (overlay.size()>0)
imp.setOverlay(overlay);
return imp;
代码示例来源:origin: net.imagej/ij
return;
int lineWidth = (int)(1.0/gel.getCanvas().getMagnification());
if (lineWidth<1)
lineWidth = 1;
Font f = new Font("Helvetica", Font.PLAIN, 12*lineWidth);
ImageProcessor ip = gel.getProcessor();
ImageProcessor ipLanes = ip.duplicate();
if (!(ipLanes instanceof ByteProcessor))
ipLanes = ipLanes.convertToByte(true);
ipLanes.setFont(f);
ipLanes.setLineWidth(lineWidth);
setCustomLut(ipLanes);
ImagePlus lanes = new ImagePlus("Lanes of "+gel.getShortTitle(), ipLanes);
lanes.changes = true;
lanes.setRoi(gel.getRoi());
gel.deleteRoi();
for (int i=0; i<overlay.size(); i++) {
Roi roi = overlay.get(i);
Rectangle r = roi.getBounds();
ipLanes.drawRect(r.x, r.y, r.width, r.height);
String s = ""+(i+1);
代码示例来源:origin: net.imagej/ij
public static void labelHyperstack(ImagePlus imp) {
int width = imp.getWidth();
int height = imp.getHeight();
int c = imp.getNChannels();
Overlay overlay = new Overlay();
int n = stack.getSize();
int yloc = 30;
IJ.showProgress(i, n);
ImageProcessor ip = stack.getProcessor(i);
ip.setAntialiasedText(true);
ip.setColor(Color.black);
ip.setRoi(0, 0, width, yloc);
String text = "c="+IJ.pad(channel,3)+", z="+IJ.pad(slice,3)+", t="+IJ.pad(frame,3)+", i="+IJ.pad(i,4);
else
roi.setPosition(i);
overlay.add(roi);
roi.setStrokeColor(Color.white);
roi.setPosition(0, 1, 1);
overlay.add(roi);
代码示例来源:origin: net.imagej/ij
/** Flattens Overlay 'overlay' on slice 'slice' corresponding to
* coordinates 'z' and 't' in RGB-HyperStack 'stack'
*/
private void flattenImage(ImageStack stack, int slice, Overlay overlay, boolean showAll, int z, int t) {
ImageProcessor ips = stack.getProcessor(slice);
ImagePlus imp1 = new ImagePlus("temp", ips);
int w = imp1.getWidth();
int h = imp1.getHeight();
for (int i=0; i<overlay.size(); i++) {
Roi r = overlay.get(i);
int cPos = r.getCPosition();// 0 or 1 (RGB-HyperStack)
int zPos = r.getZPosition();
int tPos = r.getTPosition();
if (!((cPos==1 || cPos==0) && (zPos==z || zPos==0) && (tPos==t || tPos==0) || showAll))
r.setLocation(w, h);
}
imp1.setOverlay(overlay);
ImagePlus imp2 = imp1.flatten();
stack.setPixels(imp2.getProcessor().getPixels(), slice);
}
代码示例来源:origin: net.imagej/ij
/** Flattens Overlay 'overlay' on slice 'slice' of ImageStack 'stack'.
* Copied from OverlayCommands by Marcel Boeglin 2014.01.08.
*/
private void flattenImage(ImageStack stack, int slice, Overlay overlay, boolean showAll) {
ImageProcessor ips = stack.getProcessor(slice);
ImagePlus imp1 = new ImagePlus("temp", ips);
int w = imp1.getWidth();
int h = imp1.getHeight();
for (int i=0; i<overlay.size(); i++) {
Roi r = overlay.get(i);
int roiPosition = r.getPosition();
//IJ.log(slice+" "+i+" "+roiPosition+" "+showAll+" "+overlay.size());
if (!(roiPosition==0 || roiPosition==slice || showAll))
r.setLocation(w, h);
}
imp1.setOverlay(overlay);
ImagePlus imp2 = imp1.flatten();
stack.setPixels(imp2.getProcessor().getPixels(), slice);
}
代码示例来源:origin: net.imagej/ij
public void run(String arg) {
imp = IJ.getImage();
Roi roi = imp.getRoi();
if (roi!=null && !roi.isArea())
imp.deleteRoi(); // ignore any line selection
ImageProcessor ip = imp.getProcessor();
if (!showDialog(ip))
return;
processStack = true;
if ((ip.getWidth()>1 && ip.getHeight()>1) || newWindow)
ip.setInterpolationMethod(interpolationMethod);
else
ip.setInterpolationMethod(ImageProcessor.NONE);
if (imp.getHideOverlay())
overlay = null;
if (overlay!=null && overlay.size()!=1)
overlay = null;
if (overlay!=null)
overlay = overlay.duplicate();
scale(ip, overlay);
IJ.outOfMemory("Scale");
IJ.showProgress(1.0);
代码示例来源:origin: net.imagej/ij
if (overlayClipboard==null)
interp.error("Overlay clipboard empty");
getImage().setOverlay(overlayClipboard);
return Double.NaN;
} else if (name.equals("drawLabels")) {
overlayDrawLabels = getBooleanArg();
Overlay overlay = imp.getOverlay();
if (overlay!=null) {
overlay.drawLabels(overlayDrawLabels);
imp.draw();
if (overlay==null)
interp.error("No overlay");
int size = overlay.size();
if (name.equals("size")||name.equals("getSize"))
return size;
int index = (int)getArg();
checkIndex(index, 0, size-1);
overlay.remove(index);
int index = (int)getArg();
checkIndex(index, 0, size-1);
Roi roi = overlay.get(index);
if (roi==null)
int y = (int)getLastArg();
checkIndex(index, 0, size-1);
Roi roi = overlay.get(index);
代码示例来源:origin: net.imagej/ij
private void scale(ImageProcessor ip, Overlay overlay) {
if (newWindow) {
Rectangle r = ip.getRoi();
ImagePlus imp2 = imp.createImagePlus();
imp2.setProcessor(title, ip.resize(newWidth, newHeight, averageWhenDownsizing));
Calibration cal = imp2.getCalibration();
if (cal.scaled()) {
cal.pixelWidth *= 1.0/xscale;
Roi roi = overlay.get(0);
Rectangle bounds = roi.getBounds();
if (roi instanceof ImageRoi && bounds.x==0 && bounds.y==0) {
ImageRoi iroi = (ImageRoi)roi;
ImageProcessor processor = iroi.getProcessor();
processor.setInterpolationMethod(interpolationMethod);
processor =processor.resize(newWidth, newHeight, averageWhenDownsizing);
iroi.setProcessor(processor);
imp2.setOverlay(new Overlay(iroi));
代码示例来源:origin: net.imagej/ij
if (IJ.debugMode) IJ.log("flattenStack");
if (getStackSize()==1)
throw new UnsupportedOperationException("Image stack required");
boolean composite = isComposite();
if (getBitDepth()!=24)
new ImageConverter(this).convertToRGB();
Overlay overlay1 = getOverlay();
ImageCanvas ic = getCanvas();
if (ic!=null)
roiManagerOverlay = ic.getShowAllList();
setOverlay(null);
if (roiManagerOverlay!=null) {
if (composite && overlay2==null)
return;
if (overlay2==null||overlay2.size()==0)
throw new UnsupportedOperationException("A non-empty overlay is required");
ImageStack stack2 = getStack();
for (int t=1; t<=getNFrames(); t++) {
int s = z + (t-1)*Z;
flattenImage(stack2, s, overlay2.duplicate(), showAll, z, t);
for (int s=1; s<=stack2.getSize(); s++) {
flattenImage(stack2, s, overlay2.duplicate(), showAll);
代码示例来源:origin: net.imagej/ij
Roi roi2 = getRoi();
Overlay overlay2 = getOverlay();
if (roi2==null && overlay2==null)
throw new IllegalArgumentException("ROI or overlay required");
ByteProcessor mask = new ByteProcessor(getWidth(),getHeight());
mask.setColor(255);
if (roi2!=null)
mask.fill(roi2);
else if (overlay2!=null) {
if (overlay2.size()==1 && (overlay2.get(0) instanceof ImageRoi)) {
ImageRoi iRoi = (ImageRoi)overlay2.get(0);
ImageProcessor ip = iRoi.getProcessor();
if (ip.getWidth()!=mask.getWidth() || ip.getHeight()!=mask.getHeight())
return mask;
for (int i=0; i<ip.getPixelCount(); i++) {
if (ip.get(i)!=0)
mask.set(i, 255);
for (int i=0; i<overlay2.size(); i++)
mask.fill(overlay2.get(i));
代码示例来源:origin: net.imagej/ij
void drawGrid(Shape shape) {
if (shape==null) {
Overlay overlay = imp.getOverlay();
if (overlay!=null) {
if (overlay.size()>1) {
overlay.remove(GRID);
imp.draw();
} else
imp.setOverlay(null);
roi.setStrokeColor(Colors.getColor(color,Color.cyan));
if (bold && linesV*linesH<5000) {
ImageCanvas ic = imp.getCanvas();
double mag = ic!=null?ic.getMagnification():1.0;
double width = 2.0;
if (mag<1.0)
width = width/mag;
roi.setStrokeWidth(width);
IJ.showStatus(linesV*linesH+" nodes");
Overlay overlay = imp.getOverlay();
if (overlay!=null)
overlay.remove(GRID);
else
overlay = new Overlay();
overlay.add(roi, GRID);
imp.setOverlay(overlay);
代码示例来源:origin: net.preibisch/multiview-reconstruction
Roi roi = imp.getRoi();
if ( roi == null || roi.getType() != Roi.RECTANGLE )
imp.setRoi( new Rectangle( standardRectangle ) );
roi = imp.getRoi();
roiChanged = true;
final Rectangle rect = roi.getBounds();
o = new Overlay();
imp.setOverlay( o );
o.clear();
or.setStrokeColor( Color.red );
o.add( or );
代码示例来源:origin: net.imagej/ij
private void showToolSize(int deltaWidth, ImagePlus imp) {
if (deltaWidth !=0) {
width = oldWidth + deltaWidth;
if (width<1) width=1;
Roi circle = new OvalRoi(xStart-width/2, yStart-width/2, width, width);
circle.setName(CIRCLE_NAME);
circle.setStrokeColor(Color.red);
overlay = imp.getOverlay();
if (overlay==null)
overlay = new Overlay();
else if (overlay.size()>0 && CIRCLE_NAME.equals(overlay.get(overlay.size()-1).getName()))
overlay.remove(overlay.size()-1);
overlay.add(circle);
imp.setOverlay(overlay);
}
IJ.showStatus((isPencil?"Pencil":"Brush")+" width: "+ width);
}
代码示例来源:origin: net.imagej/ij
private void changeBrushSize(float deltaWidth, ImagePlus imp) {
if (deltaWidth!=0) {
Overlay overlay = imp.getOverlay();
width = oldWidth + deltaWidth;
if (width < 0) width = 0;
Roi circle = new OvalRoi(xStart-width/2, yStart-width/2, width, width);
circle.setStrokeColor(Color.red);
overlay = imp.getOverlay();
if (overlay==null)
overlay = new Overlay();
if (mode == RESIZED)
overlay.remove(overlay.size()-1);
overlay.add(circle);
imp.setOverlay(overlay);
}
IJ.showStatus("Overlay Brush width: "+IJ.d2s(width));
mode = RESIZED;
}
代码示例来源:origin: ijpb/MorphoLibJ
int slice = displayImage.getCurrentSlice();
roi = new ImageRoi(0, 0, resultImage.getImageStack().getProcessor( slice ) );
roi.setOpacity( 1.0 );
ImageProcessor lines = BinaryImages.binarize( resultImage.getImageStack().getProcessor( slice ) );
lines.invert();
lines.setLut( LUT.createLutFromColor( Color.red ) );
roi = new ImageRoi( 0, 0, lines );
roi.setZeroTransparent( true );
roi = new ImageRoi(0, 0, BinaryImages.binarize( resultImage.getImageStack().getProcessor( slice ) ) );
roi.setOpacity( 1.0 );
displayImage.setOverlay( new Overlay( roi ) );
内容来源于网络,如有侵权,请联系作者删除!