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

Method makeBand

ij/src/main/java/ij/plugin/Selection.java:907–984  ·  view source on GitHub ↗
(ImagePlus imp)

Source from the content-addressed store, hash-verified

905 }
906
907 private void makeBand(ImagePlus imp) {
908 Roi roi = imp.getRoi();
909 if (roi==null) {
910 noRoi("Make Band");
911 return;
912 }
913 Roi roiOrig = roi;
914 if (!roi.isArea()) {
915 IJ.error("Make Band", "Area selection required");
916 return;
917 }
918 Calibration cal = imp.getCalibration();
919 double pixels = bandSize;
920 double size = pixels*cal.pixelWidth;
921 int decimalPlaces = 0;
922 if ((int)size!=size)
923 decimalPlaces = 2;
924 GenericDialog gd = new GenericDialog("Make Band");
925 gd.addNumericField("Band Size:", size, decimalPlaces, 4, cal.getUnits());
926 gd.showDialog();
927 if (gd.wasCanceled())
928 return;
929 size = gd.getNextNumber();
930 if (Double.isNaN(size)) {
931 IJ.error("Make Band", "invalid number");
932 return;
933 }
934 int n = (int)Math.round(size/cal.pixelWidth);
935 if (n >255) {
936 IJ.error("Make Band", "Cannot make bands wider that 255 pixels");
937 return;
938 }
939 int width = imp.getWidth();
940 int height = imp.getHeight();
941 Rectangle r = roi.getBounds();
942 ImageProcessor ip = roi.getMask();
943 if (ip==null) {
944 ip = new ByteProcessor(r.width, r.height);
945 ip.invert();
946 }
947 ImageProcessor mask = new ByteProcessor(width, height);
948 mask.insert(ip, r.x, r.y);
949 ImagePlus edm = new ImagePlus("mask", mask);
950 boolean saveBlackBackground = Prefs.blackBackground;
951 Prefs.blackBackground = false;
952 int saveType = EDM.getOutputType();
953 EDM.setOutputType(EDM.BYTE_OVERWRITE);
954 IJ.run(edm, "Distance Map", "");
955 EDM.setOutputType(saveType);
956 Prefs.blackBackground = saveBlackBackground;
957 ip = edm.getProcessor();
958 ip.setThreshold(0, n, ImageProcessor.NO_LUT_UPDATE);
959 int xx=-1, yy=-1; //will become the start position for the Wand
960 for (int y=Math.max(r.y,0); y<Math.min(r.y+r.height, height); y++) {
961 for (int x=Math.max(r.x,0); x<Math.min(r.x+r.width, width); x++) {
962 if (ip.getPixel(x, y)<n) {
963 xx=x; yy=y;
964 break;

Callers 1

runMethod · 0.95

Calls 15

noRoiMethod · 0.95
isAreaMethod · 0.95
errorMethod · 0.95
addNumericFieldMethod · 0.95
getUnitsMethod · 0.95
showDialogMethod · 0.95
wasCanceledMethod · 0.95
getNextNumberMethod · 0.95
getBoundsMethod · 0.95
getMaskMethod · 0.95
invertMethod · 0.95
getOutputTypeMethod · 0.95

Tested by

no test coverage detected