Skip to main content

How to convert between voxel and mm coordinates using Python

I'm often asked how to go from voxel and mm coordinates using Python. This can be easily achieved using nibabel package with only few lines of code. The following tutorial is based on +Matthew Brett answer on the nipy mailing list.

Going from voxel to mm coordinates

import os
import nibabel as nib

Load the NIFTI file defining the space you are interested in. For the purpose of this tutorial we will use a test dataset shipped with nibabel.

data_fname = os.path.join(os.path.dirname(nib.__file__), 'tests', 'data', 'example4d.nii.gz')
img = nib.load(data_fname)

Get the affine matrix and convert the coordinates.


aff = img.get_affine()
real_pt = nib.affines.apply_affine(aff, [22, 34, 12])
real_pt
array([ 73.85510254, 27.1169095 , 29.79324198])

Going from mm to voxel coordinates

Going the other direction is even easier.

import numpy.linalg as npl
nib.affines.apply_affine(npl.inv(aff), real_pt)
array([ 22., 34., 12.])

Comments

  1. This is ansuperior writing service point that doesn't always sink in within the context of the classroom. In the first superior writing service paragraph you either hook the reader's interest or lose it. Of course your teacher, who's getting paid to teach you how to write an good essay, 
    python Training institute in Chennai
    python Training institute in Bangalore

    ReplyDelete
  2. Thnx a lot
    But I hv tried tht but still i hv errors :(

    ReplyDelete
  3. Attend The Python Training in Hyderabad From ExcelR. Practical Python Training Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python Training in Hyderabad.
    python training in bangalore

    ReplyDelete
  4. Business Analytics or Data Analytics or data science training in hyderabad is an extremely popular, in-demand profession which requires a professional to possess sound knowledge of analysing data in all dimensions and uncover the unseen truth coupled with logic and domain knowledge to impact the top-line (increase business) and bottom-line (increase revenue). ExcelR’s Data Science curriculum is meticulously designed and delivered matching the industry needs and considered to be the best in the industry.

    ReplyDelete
  5. Attend The Course in Data Analytics From ExcelR. Practical Course in Data Analytics Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Course in Data Analytics.
    ExcelR Course in Data Analytics

    ReplyDelete
  6. I have read your blog and I gathered some needful information from your blog.  Machine Learning Training In Bangalore

    ReplyDelete
  7. can i get the code for transforming world to voxel co-ordinates of a mhd file

    ReplyDelete
  8. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
    data analytics courses
    Data analytics Interview Questions

    ReplyDelete
  9. very good post .. I gathered some needful information from your blog.
    digital marketing courses in hyderabad

    ReplyDelete

  10. This was really one of my favorite website. ExcelR Machine Learning Course Pune Please keep on posting.

    ReplyDelete
  11. Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info.Fantastic nice. I appreciate this post.
    Data Science Course in Bangalore

    ReplyDelete
  12. Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.
    Data Science Training in Bangalore

    ReplyDelete
  13. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.

    ReplyDelete
  14. Just the way I have expected. Your website really is interesting.
    learn360digitmg artificial intelligence course

    ReplyDelete
  15. While reading this wonderful article, I came across many aspects on which I coincide with you. It made me head bound to ponder over the topic and read it over again.
    SAP training in Kolkata
    SAP course in kolkata
    SAP training institute in Kolkata

    ReplyDelete
  16. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression
    data science interview questions

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. Super site! I am Loving it!! Will return once more, Im taking your food likewise, Thanks.
    360digitmg artificial intelligence course

    ReplyDelete
  19. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
    cloud computing course in indore

    ReplyDelete
  20. Really impressed! Everything is very open and very clear clarification of issues. It contains truly facts. Your website is very valuable. Thanks for sharing.
    digital marketing course in guduvanchery

    ReplyDelete
  21. Amazing knowledge and I like to share this kind of information with my friends and hope they like it they why I dohttps://360digitmg.com/course/certification-program-in-data-science

    ReplyDelete
  22. Amazing post found to be very impressive while going through this post. Thanks for sharing and keep posting such an informative content.

    360DigiTMG Data Analytics Course

    ReplyDelete
  23. The content is well recognized, so no one could claim that it is just one person's opinion yet it covers and justifies all the valid points. Hope to read some more work from you.
    Data Science training in Mumbai
    Data Science course in Mumbai
    SAP training in Mumbai

    ReplyDelete
  24. Truly amazing post found to be very impressive while going through this post. Thanks for sharing and keep posting such an informative content.

    Data Science Course in Raipur

    ReplyDelete
  25. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
    https://360digitmg.com/india/cloud-computing-course-in-guduvanchery

    ReplyDelete
  26. Extraordinary blog went amazed with the content they have developed in a very descriptive manner. Hope you deliver the same near the future as well. Gratitude to the blogger for the efforts.

    360DigiTMG Cloud Computing Course

    ReplyDelete
  27. cool stuff you have and you keep overhaul every one of us
    Data Analyst Course

    ReplyDelete
  28. Wonderful blog filed with useful information thanks for sharing.
    Data Science Training 360DigiTMG

    ReplyDelete
  29. This is a great post I saw thanks to sharing. I really want to hope that you will continue to share great posts in the future.
    data science courses in delhi

    ReplyDelete
  30. Nice information and thumbs up guys your doing a really good job.
    unindent does not match any outer indentation level

    ReplyDelete
  31. Very nice blog and very happy to visit your blog. Now I am found which I actually want. I check your blog everyday and try to learn something from your blog.
    unindent does not match any outer indentation level python

    ReplyDelete
  32. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts.
    a href="https://www.excelr.com/data-analytics-certification-training-course-in-pune/"> Data Analytics Course in Pune/">You re in point of fact a just right webmaster. The website loading speed is amazing. It kind of feels that you're doing any distinctive trick. Moreover, The contents are masterpiece. you have done a fantastic activity on this subject!
    I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon…

    ReplyDelete
  33. This is a great post I saw thanks to sharing. I really want to hope that you will continue to share great posts in the future.
    https://360digitmg.com/india/data-science-using-python-and-r-programming-noida

    ReplyDelete
  34. I think I have never seen such blogs ever before that has complete things with all details which I want. So kindly update this ever for us.
    best digital marketing courses in hyderabad

    ReplyDelete
  35. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!

    data science course in India

    ReplyDelete
  36. I feel extremely glad to have seen your site page and anticipate such a large number of additionally engaging occasions perusing here. Much obliged again for all the subtleties.
    data science course in delhi

    ReplyDelete
  37. this is wonderful blog .i like this type of blogs
    to know more about data science u can visit the site
    https://socialprachar.com/

    ReplyDelete
  38. This post is good enough to make somebody understand this amazing thing, and I’m sure everyone will appreciate this interesting things.
    business analytics course

    ReplyDelete
  39. Thanks for the best blog. it was very useful for me.keep sharing such ideas in the future as well.
    business analytics course

    ReplyDelete
  40. Terrific post thoroughly enjoyed reading the blog and more over found to be the tremendous one. In fact, educating the participants with it's amazing content. Hope you share the similar content consecutively.

    Data Science training

    ReplyDelete
  41. Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info.Fantastic nice. I appreciate this post.
    business analytics course

    ReplyDelete
  42. I am overwhelmed by your post with such a nice topic. Usually I visit your blogs and get updated through the information you include but today’s blog would be the most appreciable. Well done!
    Best Institute for Data Science in Hyderabad

    ReplyDelete
  43. ExcelR provides Data Science course. It is a great platform for those who want to learn and become a Data Science Courses. Students are tutored by professionals who have a degree in a particular topic. It is a great opportunity to learn and grow.

    Data Science courses
    data science course in pune
    data scientist course in pune with placement
    data scientist course in pune

    ReplyDelete
  44. Appreciate your work for this blog
    Learn https://www.digitalbrolly.com/digital-marketing-course-in-hyderabad/

    ReplyDelete
  45. learn https://www.digitalbrolly.com/digital-marketing-course-in-hyderabad/

    ReplyDelete
  46. The blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents.

    Top IAS Coaching in Mumbai
    Best IAS Coaching in Mumbai

    ReplyDelete
  47. Very interesting, you have done a good job and thanks for sharing such a good blog.
    Sharepoint Course in Chennai

    ReplyDelete
  48. Thanks for sharing this blog.. very informative..
    MVC Classes in Chennai

    ReplyDelete
  49. This is very much useful information, thanks for posting.
    Digital Marketing Interview Questons and Answers

    ReplyDelete
  50. Thanks for the information about Blogspot very informative for everyone
    artificial intelligence course

    ReplyDelete
  51. great article!! sharing these type of articles is the nice one and i hope you will share an article on data science.By giving a institute like 360DigiTMG.it is one the best institute for doing certified courses
    data scientist malaysia

    ReplyDelete
  52. Your amazing insightful information entails much to me and especially to my peers. Thanks a ton; from all of us.
    data scientist training and placement

    ReplyDelete
  53. This knowledge.Excellently written article, if only all bloggers offered the same level of content as you, the internet would be a much better place. Please keep it up.
    data science course in pune

    ReplyDelete
  54. Great! Thanks the amazing detailed Article you shared, keep sharing
    Data Science Training in Pune

    ReplyDelete
  55. I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more.
    data science course

    ReplyDelete
  56. nice post, keep posting posts like these and please write a blog about Padded Bras

    ReplyDelete
  57. More impressive blog!!! Thanks for shared with us.... waiting for you upcoming data.
    Python for Data Science
    Learn Python for Data Science

    ReplyDelete
  58. Share great information about your blog , Blog really helpful for us . We read your blog , share most useful information in blog . Thanks for share your blog here . you can also visit
    school management system

    ReplyDelete
  59. Excellent Blog, I like your blog and It is very informative. Thank you
    Qlik Sense Online Training
    Qlik Sense Online Course

    ReplyDelete
  60. Thanks for posting the best information and the blog is very good data science course in Lucknow

    ReplyDelete
  61. Sharma Academy is Central Indias largest provider of Mppsc Notes and Mppsc Study Material. You will get updated MPPSC Notes as per the latest syllabus of state level psc exam in Hindi and English medium both.

    ReplyDelete

  62. I stumbled across your blog and wanted to say that I really enjoyed reading your articles. Anyway, I will subscribe to your feed and hope you post again soon.
    Data Scientist Course in India

    ReplyDelete
  63. This comment has been removed by the author.

    ReplyDelete
  64. Very good article and liked reading your post, very pleasant to share, I want to tweet this to my followers. Thank you!.
    Best Digital Marketing Institute in Hyderabad

    ReplyDelete
  65. Fantastic blog extremely good well enjoyed with the incredible informative content .
    Visit Nuaig AI Consulting

    ReplyDelete
  66. I read your excellent blog post. It's a great job. I enjoyed reading your post for the first time, thank you.
    Data Science Institutes in Bangalore

    ReplyDelete
  67. Nice blog and informative content to users. Thanks for sharing this information with us.
    Data Science Training in Hyderabad

    ReplyDelete
  68. Data analysis and data mining are used for this purpose. You might be new in this field, so you have no idea about these terms.

    ReplyDelete
  69. prevail! it may be one of the most useful blogs we've ever come across upon the situation. terrific data! Im plus an skillful in this subject matter correspondingly i can take your effort completely dexterously. thanks for the large backing. National Brothers Day Quotes

    ReplyDelete
  70. You have to learn all the required skills to transform raw data into a form that will improve the organization.

    data science training in borivali

    ReplyDelete
  71. Unleash your potential and expand your capabilities with the Data Science Certification Course.

    data analytics course in borivali

    ReplyDelete
  72. Start your career preparation with the best Data Science courses offered by 360DigiTMG. A world-class curriculum, LMS Access, assignments, and real-time project to grab a high-paying job.


    Data Science Course in Jaipur

    ReplyDelete
  73. Data Scientist is the top job in the market, as it has promising career growth and high salary packages. Start your preparation with the best Data Science training Institute 360DigiTMG today and become a successful Data Scientist.


    Data Science Course in Jaipur

    ReplyDelete
  74. Get Data Science Certification from top-ranked universities UTM, Malaysia, and IBM. We provide extensive training for the future-ready workforce.
    data science training in malaysia

    ReplyDelete
  75. Making your on-line on line casino choice might rely upon the forms of video games they have. Here are a few of the the} gaming options you may need on your preferred on-line on line casino app. From previous results to imminent occasions, DraftKings has got you covered. Deposits in all probability not|will not be} accepted from monetary accounts may be} in the name of somebody apart 바카라사이트 from the Account Holder. We usually are not a financial institution and deposited funds shall not bear any interest. Dollars may be} held in Pooled Accounts at one of many banks additionally be} eligible for FDIC pass-through insurance.

    ReplyDelete
  76. The odds are principally in your favor and they are simple to play. With over 70 years of experience, Golden Nugget provides every little thing a passionate gambler might want. Slots, jackpots, bonuses and loyalty program, it's all 우리카지노 there alongside massive range|a wide range|a wide array} of resorts and land-based casinos.

    ReplyDelete
  77. "Great post! I really enjoyed reading it and found it informative.

    React JS Training in Hyderabad!

    ReplyDelete
  78. ERP TRAINING NOIDA is a premier institute for SAP MM training in Noida that offers high-quality training and placement assistance to aspiring SAP MM professionals. With its experienced trainers, unique training methodology, and flexible training schedules, ERP TRAINING NOIDA is the perfect destination for students who want to take their SAP MM career to the next level.

    ReplyDelete
  79. Amazing content must read.
    we are excited to announce our complete full stack classes in pune.

    ReplyDelete
  80. I found the section on ensemble methods and model stacking in this post to be informative and practicaldata analytics course in chennai..

    ReplyDelete
  81. "Your tutorial on converting between voxel and mm coordinates using Python is a lifesaver! The simplicity and clarity of your explanations, along with the concise code examples, make it incredibly easy for anyone to understand and implement. Thanks for sharing this valuable resource for working with spatial data in a seamless manner!"
    Data Analytics Courses In Bangalore

    ReplyDelete
  82. Hi,
    The example code provided is clear and concise, and the tutorial effectively demonstrates how to perform these conversions using the nibabel package. It's a valuable resource for anyone working with neuroimaging data or needing to convert coordinates between voxel and real-world space.
    If anyone wants to build their career in the field of Data Analytics then chcek this article about best Data Analytics Courses in Pune:
    Data Analytics Courses in Pune

    ReplyDelete
  83. "This tutorial simplifies the voxel to mm coordinate conversion process using Python and the nibabel package. Thanks to +Matthew Brett's insights, it's now straightforward to navigate between voxel and mm coordinates effortlessly."
    Data Analytics Courses in Delhi

    ReplyDelete
  84. Thanks for sharing this post, it was great article. Unlock unparalleled exposure for your Edtech initiatives with the comprehensive 1000+ Classifieds Submission Sites List from Edtech Reader! Explore a vast array of classified submission sites meticulously curated to elevate your online visibility.
    visit Phonics online classes

    ReplyDelete
  85. Thanks for sharing this tutorial! I'm also interested in learning how to go from voxel and mm coordinates using Python. I'll definitely check out this tutorial.

    Data Analytics Courses In Bangalore

    ReplyDelete
  86. "Whether you're a recent graduate or a working professional looking to upskill, Pune has several reputable institutions offering data
    science courses."
    data science course in pune

    ReplyDelete
  87. Hello Blogger,
    This tutorial provides a clear and concise explanation of how to convert between voxel and mm coordinates using NIFTI files in Python. The step-by-step approach and code examples make it easy to follow and implement. A helpful resource for anyone working with neuroimaging data.
    Data Analytics Courses In Dubai

    ReplyDelete
  88. This detailed tutorial you shared on How to convert between voxel and mm coordinates using Python is informative and helpful.
    Data Analytics Courses in Delhi

    ReplyDelete
  89. I am so impressed with your well-written blog. Thanks for sharing this informative blog. Keep sharing more amazing blogs.
    Data Analytics Courses in Delhi

    ReplyDelete
  90. what a wonderful blog! Your technical blogs are so helpful to me. I am definitely going to share it with my friends. They will find it helpful too.
    Visit - Data Analytics Courses in Delhi

    ReplyDelete
  91. What a fantastic blog! I appreciate how much your technical posts help me. I'll absolutely let my friends know about it. They will also benefit from it.
    Data Analytics Courses in Agra


    ReplyDelete
  92. Very difficult to understand but with this post make easy to everyone. I appreciate the style of explanation.
    Data Analytics Courses In Chennai

    ReplyDelete
  93. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.

    Data Analytics courses IN UK

    ReplyDelete
  94. Converting between voxel and mm (millimeter) coordinates in Python is crucial in medical imaging and neuroscience research, enabling accurate spatial analysis in 3D images.
    In the realm of data analytics, Glasgow's Data Analytics courses provide the skills and knowledge needed to manipulate and analyze complex spatial data, allowing professionals to make data-driven decisions in a variety of fields. Please also read Data Analytics courses in Glasgow

    ReplyDelete
  95. The blog post explained very in very clear and simple way that how to go from voxel and mm coordinates using Python. Thanks for your fantastic guidance.
    data analyst courses in limerick

    ReplyDelete
  96. Great experience I got good information from your blog. Tackle reading challenges head-on with our top-notch online phonics classes designed to eliminate common challenges in literacy development.
    visit phonics online classes

    ReplyDelete
  97. This post effectively highlights the role of data science in driving business decisions and improving outcomes....... data science course fees chennai

    ReplyDelete
  98. Thank you for sharing in depth explanation and tutorial on How to convert between voxel and mm coordinates using Python.
    Digital Marketing Courses In Bhutan

    ReplyDelete
  99. Furthermore, your consideration of the challenges and potential pitfalls in spatial coordinate conversions showcases a pragmatic approach. It's evident that your blog serves as a valuable resource for developers, researchers, and enthusiasts navigating the intersection of spatial data and Python programming.

    Digital Marketing Courses In Norwich

    ReplyDelete
  100. To convert voxel to mm coordinates in Python:

    Multiply voxel coordinates by voxel size in mm.
    To convert mm to voxel coordinates, divide mm coordinates by voxel size.
    Utilize these formulas: mm_coords = voxel_coords * voxel_size and voxel_coords = mm_coords / voxel_size.
    Data Analytics courses in new york

    ReplyDelete
  101. Great post. Just what I was looking for. Thanks for sharing.

    Investment banking courses in Germany

    ReplyDelete
  102. Thank you for this amazing tutorial, really liked it.
    investment banking free course

    ReplyDelete
  103. Thank you for sharing this insightful post! Your writing style is truly captivating, and I appreciate the effort you put into crafting such valuable content. Well done!
    Investment banking courses syllabus

    ReplyDelete
  104. Hey there! This article on converting between voxel and mm coordinates using Python is super helpful. Being able to accurately convert between these coordinate systems is crucial in many scientific and medical applications. It's great to have a guide that explains how to do it using Python. Thanks for sharing!
    Data analytics courses in Rohini

    ReplyDelete
  105. Nice article you have posted here.Thank you for sharing this information
    Investment Banking courses in the UK

    ReplyDelete

Post a Comment