I am using EVIL DICOM image reader, it works well with some files, but some files give me this error: destination array was not long enough check destindex and length and the array's lower bounds I can't find the original website where I have purchased the program. Would appreciate any assistance.
By looking at the Evil DICOM code (version 0.5.7), I assume that you are using the ImageMatrix
constructor in a way that was not entirely planned for.
The constructor you are referring to takes an array of DICOM image files, where the size of each image is supposed to be the same for all images.
Upon construction, the Image
array property is dimensioned to equal the size of one image times the length of the DICOM image array in the private method IntializeMatrix
.
Next, the constructor loops over all image files and inserts the pixel data from each file into the Image
property in the AppendImageToMatrix
method. The start position of the copied pixel data in the Image
is determined by the DICOM file ImageNumber
.
If the ImageNumber
is too high in relation to the size of the Image
array, pixel data is copied to position 0 in the Image
array.
However! If the start position is equal to the length of the Image
array, which will happen if the ImageNumber
is exactly one more than the number of files, the start position will not be modified and there will be an attempt to write to a non-existing position in the Image
array!
The line where this is happening is the fourth line in AppendImageToMatrix
, which reads:
if (offset > Image.Length) { offset = 0; }
If you are building the library yourself, you might want to change the >
operator to a >=
operator, then the application will at least not throw. Alternatively, you could consider a more fail-safe handling altogether of the pixel data copying. There is not room to elaborate on that here, though :-)
I cannot right away find the ImageMatrix
class in the updated version of Evil DICOM. However, if you run into problems with the old or the new code, consider reporting these problems on the Issues tab of the Evil DICOM Github repository.
UPDATE Note that the ImageNumber
property is equal to the DICOM attribute Instance Number, tag (0020,0013).