MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / run

Method run

ij/src/main/java/ij/plugin/Resizer.java:33–220  ·  view source on GitHub ↗
(String arg)

Source from the content-addressed store, hash-verified

31 private boolean sizeToHeight;
32
33 public void run(String arg) {
34 boolean crop = arg.equals("crop");
35 ImagePlus imp = IJ.getImage();
36 ImageProcessor ip = imp.getProcessor();
37 Roi roi = imp.getRoi();
38 int bitDepth = imp.getBitDepth();
39 double min = ip.getMin();
40 double max = ip.getMax();
41 if (!imp.okToDeleteRoi())
42 return;
43 if ((roi==null||!roi.isArea()) && crop) {
44 IJ.error(crop?"Crop":"Resize", "Area selection required");
45 return;
46 }
47 if (!imp.lock()) {
48 IJ.log("<<Resizer: image is locked ("+imp+")>>");
49 return;
50 }
51 Rectangle r = ip.getRoi();
52 origWidth = r.width;;
53 origHeight = r.height;
54 sizeToHeight=false;
55 boolean restoreRoi = crop && roi!=null && roi.getType()!=Roi.RECTANGLE;
56 if (roi!=null) {
57 Rectangle b = roi.getBounds();
58 int w = ip.getWidth();
59 int h = ip.getHeight();
60 if (b.x<0 || b.y<0 || b.x+b.width>w || b.y+b.height>h) {
61 ShapeRoi shape1 = new ShapeRoi(roi);
62 ShapeRoi shape2 = new ShapeRoi(new Roi(0, 0, w, h));
63 roi = shape2.and(shape1);
64 if (roi.getBounds().width==0 || roi.getBounds().height==0) {
65 if (IJ.isMacro())
66 IJ.log("Selection is outside image");
67 else
68 throw new IllegalArgumentException("Selection is outside image");
69 }
70 if (restoreRoi) imp.setRoi(roi);
71 }
72 }
73 int stackSize= imp.getStackSize();
74 int z1 = imp.getStackSize();
75 int t1 = 0;
76 int z2=0, t2=0;
77 int saveMethod = interpolationMethod;
78 if (crop) {
79 Rectangle bounds = roi.getBounds();
80 newWidth = bounds.width;
81 newHeight = bounds.height;
82 interpolationMethod = ImageProcessor.NONE;
83 } else {
84 if (newWidth==0 || newHeight==0) {
85 newWidth = (int)origWidth/2;
86 newHeight = (int)origHeight/2;
87 }
88 if (constrain) newHeight = (int)(newWidth*(origHeight/origWidth));
89 if (stackSize>1) {
90 newWidth = (int)origWidth;

Callers

nothing calls this directly

Calls 15

getImageMethod · 0.95
getProcessorMethod · 0.95
getRoiMethod · 0.95
getBitDepthMethod · 0.95
getMinMethod · 0.95
getMaxMethod · 0.95
okToDeleteRoiMethod · 0.95
isAreaMethod · 0.95
errorMethod · 0.95
lockMethod · 0.95
logMethod · 0.95
getRoiMethod · 0.95

Tested by

no test coverage detected