Check for pixel spacing between two folder images

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
5
down vote

favorite












Im trying to match the pixel spacing between two folders, here matches has 994 keys and it shows that i may take more than a day to compute this. Is there any way i can speed up this operation.



the load series function looks like this



import SimpleITK as sitk
def load_series(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
return reader.Execute()

import csv
bar = ProgressBar()
file = open('BenignTest.csv', 'w')
writer = csv.writer(file)
for item in bar(matches.keys()):
for case in matches[item]:
load_case = load_series(case)
if load_case.GetSpacing() == load_series(item).GetSpacing():
writer.writerow((item , case))
break


The matches dictionary looks like this,



'/mnt/sdd1/DSB2017/stage1/0030a160d58723ff36d73f41b170ec21': ['/mnt/sde1/Cancer/128443/01-02-1999-LSS-59120/2-0OPAGELSPLUSD3602.512060.00.11.5-98506',
'/mnt/sde1/Cancer/213485/01-02-1999-ACRIN-13247/3-0OPAGELSPLUSLUNG3502.51204026.71.5-85097',
'/mnt/sde1/Cancer/206342/01-02-1999-ACRIN-68321/3-0OPAGELSPLUSLUNG3702.51205033.31.5-72233',
'/mnt/sde1/Cancer/200209/01-02-2000-CRIN-10216/3-1OPAGELSPLUSLUNG4002.51204026.71.5-42354']...........


Thanks in advance







share|improve this question


















  • 1




    Cross-posted from Stack Overflow
    – Mathias Ettinger
    Aug 14 at 8:02
















up vote
5
down vote

favorite












Im trying to match the pixel spacing between two folders, here matches has 994 keys and it shows that i may take more than a day to compute this. Is there any way i can speed up this operation.



the load series function looks like this



import SimpleITK as sitk
def load_series(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
return reader.Execute()

import csv
bar = ProgressBar()
file = open('BenignTest.csv', 'w')
writer = csv.writer(file)
for item in bar(matches.keys()):
for case in matches[item]:
load_case = load_series(case)
if load_case.GetSpacing() == load_series(item).GetSpacing():
writer.writerow((item , case))
break


The matches dictionary looks like this,



'/mnt/sdd1/DSB2017/stage1/0030a160d58723ff36d73f41b170ec21': ['/mnt/sde1/Cancer/128443/01-02-1999-LSS-59120/2-0OPAGELSPLUSD3602.512060.00.11.5-98506',
'/mnt/sde1/Cancer/213485/01-02-1999-ACRIN-13247/3-0OPAGELSPLUSLUNG3502.51204026.71.5-85097',
'/mnt/sde1/Cancer/206342/01-02-1999-ACRIN-68321/3-0OPAGELSPLUSLUNG3702.51205033.31.5-72233',
'/mnt/sde1/Cancer/200209/01-02-2000-CRIN-10216/3-1OPAGELSPLUSLUNG4002.51204026.71.5-42354']...........


Thanks in advance







share|improve this question


















  • 1




    Cross-posted from Stack Overflow
    – Mathias Ettinger
    Aug 14 at 8:02












up vote
5
down vote

favorite









up vote
5
down vote

favorite











Im trying to match the pixel spacing between two folders, here matches has 994 keys and it shows that i may take more than a day to compute this. Is there any way i can speed up this operation.



the load series function looks like this



import SimpleITK as sitk
def load_series(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
return reader.Execute()

import csv
bar = ProgressBar()
file = open('BenignTest.csv', 'w')
writer = csv.writer(file)
for item in bar(matches.keys()):
for case in matches[item]:
load_case = load_series(case)
if load_case.GetSpacing() == load_series(item).GetSpacing():
writer.writerow((item , case))
break


The matches dictionary looks like this,



'/mnt/sdd1/DSB2017/stage1/0030a160d58723ff36d73f41b170ec21': ['/mnt/sde1/Cancer/128443/01-02-1999-LSS-59120/2-0OPAGELSPLUSD3602.512060.00.11.5-98506',
'/mnt/sde1/Cancer/213485/01-02-1999-ACRIN-13247/3-0OPAGELSPLUSLUNG3502.51204026.71.5-85097',
'/mnt/sde1/Cancer/206342/01-02-1999-ACRIN-68321/3-0OPAGELSPLUSLUNG3702.51205033.31.5-72233',
'/mnt/sde1/Cancer/200209/01-02-2000-CRIN-10216/3-1OPAGELSPLUSLUNG4002.51204026.71.5-42354']...........


Thanks in advance







share|improve this question














Im trying to match the pixel spacing between two folders, here matches has 994 keys and it shows that i may take more than a day to compute this. Is there any way i can speed up this operation.



the load series function looks like this



import SimpleITK as sitk
def load_series(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
return reader.Execute()

import csv
bar = ProgressBar()
file = open('BenignTest.csv', 'w')
writer = csv.writer(file)
for item in bar(matches.keys()):
for case in matches[item]:
load_case = load_series(case)
if load_case.GetSpacing() == load_series(item).GetSpacing():
writer.writerow((item , case))
break


The matches dictionary looks like this,



'/mnt/sdd1/DSB2017/stage1/0030a160d58723ff36d73f41b170ec21': ['/mnt/sde1/Cancer/128443/01-02-1999-LSS-59120/2-0OPAGELSPLUSD3602.512060.00.11.5-98506',
'/mnt/sde1/Cancer/213485/01-02-1999-ACRIN-13247/3-0OPAGELSPLUSLUNG3502.51204026.71.5-85097',
'/mnt/sde1/Cancer/206342/01-02-1999-ACRIN-68321/3-0OPAGELSPLUSLUNG3702.51205033.31.5-72233',
'/mnt/sde1/Cancer/200209/01-02-2000-CRIN-10216/3-1OPAGELSPLUSLUNG4002.51204026.71.5-42354']...........


Thanks in advance









share|improve this question













share|improve this question




share|improve this question








edited Aug 14 at 8:37

























asked Aug 14 at 7:38









Ryan

1284




1284







  • 1




    Cross-posted from Stack Overflow
    – Mathias Ettinger
    Aug 14 at 8:02












  • 1




    Cross-posted from Stack Overflow
    – Mathias Ettinger
    Aug 14 at 8:02







1




1




Cross-posted from Stack Overflow
– Mathias Ettinger
Aug 14 at 8:02




Cross-posted from Stack Overflow
– Mathias Ettinger
Aug 14 at 8:02










2 Answers
2






active

oldest

votes

















up vote
4
down vote



accepted










The simplest improvement that you can do right now is to avoid recomputing the same reference image over and over for each case of an item: just store load_series(item).GetSpacing() before looping over each case.



You can also use writer.writerows and feed it a list or a generator instead of writer.writerow. This should optimize disk writes a bit, even though reading images should be the task that take up the most resources here.



Proposed improvements:



import csv
import SimpleITK as sitk


def load_series(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
return reader.Execute()


def generate_equal_spacing(matches, progress_bar=None):
items = matches.keys()
if progress_bar is not None:
items = progress_bar(items)

for item in items:
reference_spacing = load_series(item).GetSpacing()
for case in matches[item]:
if load_series(case).GetSpacing() == reference_spacing:
yield (item, case)
break


def main(matches, output_filename='BenignTest.csv'):
with open(output_filename, 'w') as f:
writer = csv.writer(f)
writer.writerows(generate_equal_spacing(matches, ProgressBar()))


if __name__ == '__main__':
main(
'/mnt/sdd1/DSB2017/stage1/0030a160d58723ff36d73f41b170ec21': [
'/mnt/sde1/Cancer/128443/01-02-1999-LSS-59120/2-0OPAGELSPLUSD3602.512060.00.11.5-98506',
'/mnt/sde1/Cancer/213485/01-02-1999-ACRIN-13247/3-0OPAGELSPLUSLUNG3502.51204026.71.5-85097',
'/mnt/sde1/Cancer/206342/01-02-1999-ACRIN-68321/3-0OPAGELSPLUSLUNG3702.51205033.31.5-72233',
'/mnt/sde1/Cancer/200209/01-02-2000-CRIN-10216/3-1OPAGELSPLUSLUNG4002.51204026.71.5-42354',
],
...
)





share|improve this answer
















  • 2




    In addition: functools.lru_cache may increase performance further if a lot of the files are the same.
    – Peilonrayz
    Aug 14 at 8:51

















up vote
2
down vote













If you just want each image's spacing information, you don't actually need to read the images, just the header info.



Here is a SimpleITK example showing how to read an image's meta-data information without loading the pixels.



https://simpleitk.readthedocs.io/en/latest/Examples/DicomImagePrintTags/Documentation.html



So change your load_series function something like this:



def load_series_spacing(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
reader.ReadImageInformation();
return reader.GetSpacing()


And then, of course, adjust the comparisons in the main routine accordingly, since we're returning spacing, not the actual images.






share|improve this answer




















  • Hi Dave, Thanks for your inputs, But when i run your function, i get this AttributeError: 'ImageSeriesReader' object has no attribute 'ReadImageInformation' any ideas on this ?
    – Ryan
    Aug 20 at 8:51











  • Oops, my bad. The method ReadImageInformation is in the class ImageFileReader, not ImageSeriesReader. So you can get the header info for each individual slice. Then GetSpacing would return the X-Y pixel spacing. If you want the Z spacing, you'll have to do some math from the Origins of neighboring slices.
    – Dave Chen
    Aug 20 at 14:33











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f201646%2fcheck-for-pixel-spacing-between-two-folder-images%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










The simplest improvement that you can do right now is to avoid recomputing the same reference image over and over for each case of an item: just store load_series(item).GetSpacing() before looping over each case.



You can also use writer.writerows and feed it a list or a generator instead of writer.writerow. This should optimize disk writes a bit, even though reading images should be the task that take up the most resources here.



Proposed improvements:



import csv
import SimpleITK as sitk


def load_series(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
return reader.Execute()


def generate_equal_spacing(matches, progress_bar=None):
items = matches.keys()
if progress_bar is not None:
items = progress_bar(items)

for item in items:
reference_spacing = load_series(item).GetSpacing()
for case in matches[item]:
if load_series(case).GetSpacing() == reference_spacing:
yield (item, case)
break


def main(matches, output_filename='BenignTest.csv'):
with open(output_filename, 'w') as f:
writer = csv.writer(f)
writer.writerows(generate_equal_spacing(matches, ProgressBar()))


if __name__ == '__main__':
main(
'/mnt/sdd1/DSB2017/stage1/0030a160d58723ff36d73f41b170ec21': [
'/mnt/sde1/Cancer/128443/01-02-1999-LSS-59120/2-0OPAGELSPLUSD3602.512060.00.11.5-98506',
'/mnt/sde1/Cancer/213485/01-02-1999-ACRIN-13247/3-0OPAGELSPLUSLUNG3502.51204026.71.5-85097',
'/mnt/sde1/Cancer/206342/01-02-1999-ACRIN-68321/3-0OPAGELSPLUSLUNG3702.51205033.31.5-72233',
'/mnt/sde1/Cancer/200209/01-02-2000-CRIN-10216/3-1OPAGELSPLUSLUNG4002.51204026.71.5-42354',
],
...
)





share|improve this answer
















  • 2




    In addition: functools.lru_cache may increase performance further if a lot of the files are the same.
    – Peilonrayz
    Aug 14 at 8:51














up vote
4
down vote



accepted










The simplest improvement that you can do right now is to avoid recomputing the same reference image over and over for each case of an item: just store load_series(item).GetSpacing() before looping over each case.



You can also use writer.writerows and feed it a list or a generator instead of writer.writerow. This should optimize disk writes a bit, even though reading images should be the task that take up the most resources here.



Proposed improvements:



import csv
import SimpleITK as sitk


def load_series(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
return reader.Execute()


def generate_equal_spacing(matches, progress_bar=None):
items = matches.keys()
if progress_bar is not None:
items = progress_bar(items)

for item in items:
reference_spacing = load_series(item).GetSpacing()
for case in matches[item]:
if load_series(case).GetSpacing() == reference_spacing:
yield (item, case)
break


def main(matches, output_filename='BenignTest.csv'):
with open(output_filename, 'w') as f:
writer = csv.writer(f)
writer.writerows(generate_equal_spacing(matches, ProgressBar()))


if __name__ == '__main__':
main(
'/mnt/sdd1/DSB2017/stage1/0030a160d58723ff36d73f41b170ec21': [
'/mnt/sde1/Cancer/128443/01-02-1999-LSS-59120/2-0OPAGELSPLUSD3602.512060.00.11.5-98506',
'/mnt/sde1/Cancer/213485/01-02-1999-ACRIN-13247/3-0OPAGELSPLUSLUNG3502.51204026.71.5-85097',
'/mnt/sde1/Cancer/206342/01-02-1999-ACRIN-68321/3-0OPAGELSPLUSLUNG3702.51205033.31.5-72233',
'/mnt/sde1/Cancer/200209/01-02-2000-CRIN-10216/3-1OPAGELSPLUSLUNG4002.51204026.71.5-42354',
],
...
)





share|improve this answer
















  • 2




    In addition: functools.lru_cache may increase performance further if a lot of the files are the same.
    – Peilonrayz
    Aug 14 at 8:51












up vote
4
down vote



accepted







up vote
4
down vote



accepted






The simplest improvement that you can do right now is to avoid recomputing the same reference image over and over for each case of an item: just store load_series(item).GetSpacing() before looping over each case.



You can also use writer.writerows and feed it a list or a generator instead of writer.writerow. This should optimize disk writes a bit, even though reading images should be the task that take up the most resources here.



Proposed improvements:



import csv
import SimpleITK as sitk


def load_series(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
return reader.Execute()


def generate_equal_spacing(matches, progress_bar=None):
items = matches.keys()
if progress_bar is not None:
items = progress_bar(items)

for item in items:
reference_spacing = load_series(item).GetSpacing()
for case in matches[item]:
if load_series(case).GetSpacing() == reference_spacing:
yield (item, case)
break


def main(matches, output_filename='BenignTest.csv'):
with open(output_filename, 'w') as f:
writer = csv.writer(f)
writer.writerows(generate_equal_spacing(matches, ProgressBar()))


if __name__ == '__main__':
main(
'/mnt/sdd1/DSB2017/stage1/0030a160d58723ff36d73f41b170ec21': [
'/mnt/sde1/Cancer/128443/01-02-1999-LSS-59120/2-0OPAGELSPLUSD3602.512060.00.11.5-98506',
'/mnt/sde1/Cancer/213485/01-02-1999-ACRIN-13247/3-0OPAGELSPLUSLUNG3502.51204026.71.5-85097',
'/mnt/sde1/Cancer/206342/01-02-1999-ACRIN-68321/3-0OPAGELSPLUSLUNG3702.51205033.31.5-72233',
'/mnt/sde1/Cancer/200209/01-02-2000-CRIN-10216/3-1OPAGELSPLUSLUNG4002.51204026.71.5-42354',
],
...
)





share|improve this answer












The simplest improvement that you can do right now is to avoid recomputing the same reference image over and over for each case of an item: just store load_series(item).GetSpacing() before looping over each case.



You can also use writer.writerows and feed it a list or a generator instead of writer.writerow. This should optimize disk writes a bit, even though reading images should be the task that take up the most resources here.



Proposed improvements:



import csv
import SimpleITK as sitk


def load_series(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
return reader.Execute()


def generate_equal_spacing(matches, progress_bar=None):
items = matches.keys()
if progress_bar is not None:
items = progress_bar(items)

for item in items:
reference_spacing = load_series(item).GetSpacing()
for case in matches[item]:
if load_series(case).GetSpacing() == reference_spacing:
yield (item, case)
break


def main(matches, output_filename='BenignTest.csv'):
with open(output_filename, 'w') as f:
writer = csv.writer(f)
writer.writerows(generate_equal_spacing(matches, ProgressBar()))


if __name__ == '__main__':
main(
'/mnt/sdd1/DSB2017/stage1/0030a160d58723ff36d73f41b170ec21': [
'/mnt/sde1/Cancer/128443/01-02-1999-LSS-59120/2-0OPAGELSPLUSD3602.512060.00.11.5-98506',
'/mnt/sde1/Cancer/213485/01-02-1999-ACRIN-13247/3-0OPAGELSPLUSLUNG3502.51204026.71.5-85097',
'/mnt/sde1/Cancer/206342/01-02-1999-ACRIN-68321/3-0OPAGELSPLUSLUNG3702.51205033.31.5-72233',
'/mnt/sde1/Cancer/200209/01-02-2000-CRIN-10216/3-1OPAGELSPLUSLUNG4002.51204026.71.5-42354',
],
...
)






share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 14 at 8:43









Mathias Ettinger

22k32876




22k32876







  • 2




    In addition: functools.lru_cache may increase performance further if a lot of the files are the same.
    – Peilonrayz
    Aug 14 at 8:51












  • 2




    In addition: functools.lru_cache may increase performance further if a lot of the files are the same.
    – Peilonrayz
    Aug 14 at 8:51







2




2




In addition: functools.lru_cache may increase performance further if a lot of the files are the same.
– Peilonrayz
Aug 14 at 8:51




In addition: functools.lru_cache may increase performance further if a lot of the files are the same.
– Peilonrayz
Aug 14 at 8:51












up vote
2
down vote













If you just want each image's spacing information, you don't actually need to read the images, just the header info.



Here is a SimpleITK example showing how to read an image's meta-data information without loading the pixels.



https://simpleitk.readthedocs.io/en/latest/Examples/DicomImagePrintTags/Documentation.html



So change your load_series function something like this:



def load_series_spacing(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
reader.ReadImageInformation();
return reader.GetSpacing()


And then, of course, adjust the comparisons in the main routine accordingly, since we're returning spacing, not the actual images.






share|improve this answer




















  • Hi Dave, Thanks for your inputs, But when i run your function, i get this AttributeError: 'ImageSeriesReader' object has no attribute 'ReadImageInformation' any ideas on this ?
    – Ryan
    Aug 20 at 8:51











  • Oops, my bad. The method ReadImageInformation is in the class ImageFileReader, not ImageSeriesReader. So you can get the header info for each individual slice. Then GetSpacing would return the X-Y pixel spacing. If you want the Z spacing, you'll have to do some math from the Origins of neighboring slices.
    – Dave Chen
    Aug 20 at 14:33















up vote
2
down vote













If you just want each image's spacing information, you don't actually need to read the images, just the header info.



Here is a SimpleITK example showing how to read an image's meta-data information without loading the pixels.



https://simpleitk.readthedocs.io/en/latest/Examples/DicomImagePrintTags/Documentation.html



So change your load_series function something like this:



def load_series_spacing(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
reader.ReadImageInformation();
return reader.GetSpacing()


And then, of course, adjust the comparisons in the main routine accordingly, since we're returning spacing, not the actual images.






share|improve this answer




















  • Hi Dave, Thanks for your inputs, But when i run your function, i get this AttributeError: 'ImageSeriesReader' object has no attribute 'ReadImageInformation' any ideas on this ?
    – Ryan
    Aug 20 at 8:51











  • Oops, my bad. The method ReadImageInformation is in the class ImageFileReader, not ImageSeriesReader. So you can get the header info for each individual slice. Then GetSpacing would return the X-Y pixel spacing. If you want the Z spacing, you'll have to do some math from the Origins of neighboring slices.
    – Dave Chen
    Aug 20 at 14:33













up vote
2
down vote










up vote
2
down vote









If you just want each image's spacing information, you don't actually need to read the images, just the header info.



Here is a SimpleITK example showing how to read an image's meta-data information without loading the pixels.



https://simpleitk.readthedocs.io/en/latest/Examples/DicomImagePrintTags/Documentation.html



So change your load_series function something like this:



def load_series_spacing(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
reader.ReadImageInformation();
return reader.GetSpacing()


And then, of course, adjust the comparisons in the main routine accordingly, since we're returning spacing, not the actual images.






share|improve this answer












If you just want each image's spacing information, you don't actually need to read the images, just the header info.



Here is a SimpleITK example showing how to read an image's meta-data information without loading the pixels.



https://simpleitk.readthedocs.io/en/latest/Examples/DicomImagePrintTags/Documentation.html



So change your load_series function something like this:



def load_series_spacing(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
reader.SetFileNames(dicom_names)
reader.ReadImageInformation();
return reader.GetSpacing()


And then, of course, adjust the comparisons in the main routine accordingly, since we're returning spacing, not the actual images.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 17 at 14:13









Dave Chen

214




214











  • Hi Dave, Thanks for your inputs, But when i run your function, i get this AttributeError: 'ImageSeriesReader' object has no attribute 'ReadImageInformation' any ideas on this ?
    – Ryan
    Aug 20 at 8:51











  • Oops, my bad. The method ReadImageInformation is in the class ImageFileReader, not ImageSeriesReader. So you can get the header info for each individual slice. Then GetSpacing would return the X-Y pixel spacing. If you want the Z spacing, you'll have to do some math from the Origins of neighboring slices.
    – Dave Chen
    Aug 20 at 14:33

















  • Hi Dave, Thanks for your inputs, But when i run your function, i get this AttributeError: 'ImageSeriesReader' object has no attribute 'ReadImageInformation' any ideas on this ?
    – Ryan
    Aug 20 at 8:51











  • Oops, my bad. The method ReadImageInformation is in the class ImageFileReader, not ImageSeriesReader. So you can get the header info for each individual slice. Then GetSpacing would return the X-Y pixel spacing. If you want the Z spacing, you'll have to do some math from the Origins of neighboring slices.
    – Dave Chen
    Aug 20 at 14:33
















Hi Dave, Thanks for your inputs, But when i run your function, i get this AttributeError: 'ImageSeriesReader' object has no attribute 'ReadImageInformation' any ideas on this ?
– Ryan
Aug 20 at 8:51





Hi Dave, Thanks for your inputs, But when i run your function, i get this AttributeError: 'ImageSeriesReader' object has no attribute 'ReadImageInformation' any ideas on this ?
– Ryan
Aug 20 at 8:51













Oops, my bad. The method ReadImageInformation is in the class ImageFileReader, not ImageSeriesReader. So you can get the header info for each individual slice. Then GetSpacing would return the X-Y pixel spacing. If you want the Z spacing, you'll have to do some math from the Origins of neighboring slices.
– Dave Chen
Aug 20 at 14:33





Oops, my bad. The method ReadImageInformation is in the class ImageFileReader, not ImageSeriesReader. So you can get the header info for each individual slice. Then GetSpacing would return the X-Y pixel spacing. If you want the Z spacing, you'll have to do some math from the Origins of neighboring slices.
– Dave Chen
Aug 20 at 14:33


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f201646%2fcheck-for-pixel-spacing-between-two-folder-images%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery