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

Method run

ij/src/main/java/ij/plugin/DICOM.java:89–175  ·  view source on GitHub ↗
(String arg)

Source from the content-addressed store, hash-verified

87 }
88
89 public void run(String arg) {
90 OpenDialog od = new OpenDialog("Open Dicom...", arg);
91 String directory = od.getDirectory();
92 String fileName = od.getFileName();
93 if (fileName==null)
94 return;
95 DicomDecoder dd = new DicomDecoder(directory, fileName);
96 dd.inputStream = inputStream;
97 FileInfo fi = null;
98 try {
99 fi = dd.getFileInfo();
100 } catch (IOException e) {
101 String msg = e.getMessage();
102 IJ.showStatus("");
103 if (msg.indexOf("EOF")<0&&showErrors) {
104 IJ.error("DICOM Reader", e.getClass().getName()+"\n \n"+msg);
105 return;
106 } else if (!dd.dicmFound()&&showErrors) {
107 msg = "This does not appear to be a valid\n"
108 + "DICOM file. It does not have the\n"
109 + "characters 'DICM' at offset 128.";
110 IJ.error("DICOM Reader", msg);
111 return;
112 }
113 }
114 if (gettingInfo) {
115 info = dd.getDicomInfo();
116 return;
117 }
118 if (fi!=null && fi.width>0 && fi.height>0 && fi.offset>0) {
119 FileOpener fo = new FileOpener(fi);
120 ImagePlus imp = fo.openImage();
121 // Avoid opening as float even if slope != 1.0 in case ignoreRescaleSlope or fixedDicomScaling
122 // were checked in the DICOM preferences.
123 boolean openAsFloat = (dd.rescaleSlope!=1.0 && !(Prefs.ignoreRescaleSlope || Prefs.fixedDicomScaling))
124 || Prefs.openDicomsAsFloat;
125 String options = Macro.getOptions();
126 if (openAsFloat) {
127 IJ.run(imp, "32-bit", "");
128 if (dd.rescaleSlope!=1.0)
129 IJ.run(imp, "Multiply...", "value="+dd.rescaleSlope+" stack");
130 if (dd.rescaleIntercept!=0.0)
131 IJ.run(imp, "Add...", "value="+dd.rescaleIntercept+" stack");
132 if (imp.getStackSize()>1) {
133 imp.setSlice(imp.getStackSize()/2);
134 ImageStatistics stats = imp.getRawStatistics();
135 imp.setDisplayRange(stats.min,stats.max);
136 }
137 } else if (fi.fileType==FileInfo.GRAY16_SIGNED) {
138 if (dd.rescaleIntercept!=0.0 && (dd.rescaleSlope==1.0||Prefs.fixedDicomScaling)) {
139 double[] coeff = new double[2];
140 coeff[0] = dd.rescaleSlope*(-32768) + dd.rescaleIntercept;
141 coeff[1] = dd.rescaleSlope;
142 imp.getCalibration().setFunction(Calibration.STRAIGHT_LINE, coeff, "Gray Value");
143 }
144 } else if (dd.rescaleIntercept!=0.0 &&
145 (dd.rescaleSlope==1.0||Prefs.fixedDicomScaling||fi.fileType==FileInfo.GRAY8)) {
146 double[] coeff = new double[2];

Callers 4

openMethod · 0.95
getInfoMethod · 0.95
openDicomStackMethod · 0.95
openZipMethod · 0.95

Calls 15

getDirectoryMethod · 0.95
getFileNameMethod · 0.95
getFileInfoMethod · 0.95
showStatusMethod · 0.95
errorMethod · 0.95
dicmFoundMethod · 0.95
getDicomInfoMethod · 0.95
openImageMethod · 0.95
getOptionsMethod · 0.95
runMethod · 0.95
getStackSizeMethod · 0.95
setSliceMethod · 0.95

Tested by

no test coverage detected