| 91 | } |
| 92 | |
| 93 | int |
| 94 | main(int argc, char * argv[]) |
| 95 | { |
| 96 | if (argc < 2) |
| 97 | { |
| 98 | std::cout << "Usage: DicomSeriesFromArray <output_directory>" << std::endl; |
| 99 | return 1; |
| 100 | } |
| 101 | |
| 102 | // Set pixel type sitkInt16 or sitkFloat64 |
| 103 | sitk::PixelIDValueEnum pixelType = sitk::sitkInt16; |
| 104 | |
| 105 | // Create image from random data array based on the pixel type |
| 106 | std::vector<unsigned int> imageSize = { 512, 512, 256 }; |
| 107 | size_t totalPixels = imageSize[0] * imageSize[1] * imageSize[2]; |
| 108 | |
| 109 | std::random_device rd; |
| 110 | std::mt19937 gen(rd()); |
| 111 | sitk::Image newImg; |
| 112 | |
| 113 | if (pixelType == sitk::sitkInt16) |
| 114 | { |
| 115 | std::uniform_int_distribution<short> dis(-1000, 1000); |
| 116 | std::vector<short> randomData(totalPixels); |
| 117 | for (size_t i = 0; i < totalPixels; ++i) |
| 118 | { |
| 119 | randomData[i] = dis(gen); |
| 120 | } |
| 121 | newImg = sitk::ImportAsInt16(randomData.data(), imageSize); |
| 122 | } |
| 123 | else if (pixelType == sitk::sitkFloat64) |
| 124 | { |
| 125 | std::uniform_real_distribution<> dis(-1000.0, 1000.0); |
| 126 | std::vector<double> randomData(totalPixels); |
| 127 | for (size_t i = 0; i < totalPixels; ++i) |
| 128 | { |
| 129 | randomData[i] = dis(gen); |
| 130 | } |
| 131 | newImg = sitk::ImportAsFloat64(randomData.data(), imageSize); |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | std::cerr << "Unsupported pixel type" << std::endl; |
| 136 | return 1; |
| 137 | } |
| 138 | |
| 139 | newImg.SetSpacing({ 2.5, 3.5, 4.5 }); |
| 140 | |
| 141 | // Write the 3D image as a series |
| 142 | // IMPORTANT: There are many DICOM tags that need to be updated when you modify |
| 143 | // an original image. This is a delicate operation and requires |
| 144 | // knowledge of the DICOM standard. This example only modifies some. |
| 145 | // For a more complete list of tags that need to be modified see: |
| 146 | // http://gdcm.sourceforge.net/wiki/index.php/Writing_DICOM |
| 147 | // If it is critical for your work to generate valid DICOM files, |
| 148 | // It is recommended to use David Clunie's Dicom3tools to validate |
| 149 | // the files: |
| 150 | // http://www.dclunie.com/dicom3tools.html |
nothing calls this directly
no test coverage detected