Calculates the voxel depth of the specified DICOM stack based on the distance between the first and last slices.
(ImageStack stack)
| 95 | /** Calculates the voxel depth of the specified DICOM stack based |
| 96 | on the distance between the first and last slices. */ |
| 97 | public static double getVoxelDepth(ImageStack stack) { |
| 98 | if (stack.isVirtual()) stack.getProcessor(1); |
| 99 | String pos0 = getTag(stack.getSliceLabel(1), "0020,0032"); |
| 100 | String posn = null; |
| 101 | double voxelDepth = -1.0; |
| 102 | if (pos0!=null) { |
| 103 | String[] xyz = pos0.split("\\\\"); |
| 104 | if (xyz.length!=3) return voxelDepth; |
| 105 | double z0 = Double.parseDouble(xyz[2]); |
| 106 | if (stack.isVirtual()) stack.getProcessor(stack.size()); |
| 107 | posn = getTag(stack.getSliceLabel(stack.size()), "0020,0032"); |
| 108 | if (posn==null) return voxelDepth; |
| 109 | xyz = posn.split("\\\\"); |
| 110 | if (xyz.length!=3) return voxelDepth; |
| 111 | double zn = Double.parseDouble(xyz[2]); |
| 112 | voxelDepth = Math.abs((zn - z0) / (stack.size() - 1)); |
| 113 | } |
| 114 | if (IJ.debugMode) IJ.log("DicomTools.getVoxelDepth: "+voxelDepth+" "+pos0+" "+posn); |
| 115 | return voxelDepth; |
| 116 | } |
| 117 | |
| 118 | /** Returns the value (as a string) of the specified DICOM tag id (in the form "0018,0050") |
| 119 | of the specified image or stack slice. Returns null if the tag id is not found. */ |
no test coverage detected