[Neuroimaging] Neuroimaging Digest, Vol 47, Issue 8

Stephen Taylor stephen.taylor at imm.ox.ac.uk
Tue Apr 30 15:17:32 EDT 2019


Hi Ariel,


Thanks for the link but I am still unsure of how this will work.


I want to input a 3d array containing x, y, z coordinates with RGB values (tuples) but the img_orig parameter expects an image instance. I don't have an image and want to write one from scratch. Ideally input an array and then return an image. Sorry if I wasn't clear in my post.


Kind regards and thanks,

Steve
----------------------------------
Head of Analysis, Visualisation and Informatics
MRC Weatherall Institute of Molecular Medicine
Oxford

________________________________
From: Neuroimaging <neuroimaging-bounces+stephen.taylor=imm.ox.ac.uk at python.org> on behalf of neuroimaging-request at python.org <neuroimaging-request at python.org>
Sent: Thursday, April 25, 2019 5:00:06 PM
To: neuroimaging at python.org
Subject: Neuroimaging Digest, Vol 47, Issue 8

Send Neuroimaging mailing list submissions to
        neuroimaging at python.org

To subscribe or unsubscribe via the World Wide Web, visit
        https://mail.python.org/mailman/listinfo/neuroimaging
or, via email, send a message with subject or body 'help' to
        neuroimaging-request at python.org

You can reach the person managing the list at
        neuroimaging-owner at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Neuroimaging digest..."


Today's Topics:

   1. Re: How to set RGB values in NiBabel (Ariel Rokem)
   2. OrthoSlicer3D (Dalton Sakthivadivel)
   3. Re: OrthoSlicer3D (Christopher Markiewicz)
   4. Re: OrthoSlicer3D (Dalton Sakthivadivel)


----------------------------------------------------------------------

Message: 1
Date: Wed, 24 Apr 2019 19:36:19 -0700
From: Ariel Rokem <arokem at gmail.com>
To: Neuroimaging analysis in Python <neuroimaging at python.org>
Subject: Re: [Neuroimaging] How to set RGB values in NiBabel
Message-ID:
        <CA+X4w0ywfi6GNywS8Mtx=nhvTFMXyJ2odtCKJW3Tn_8aSMvGtg at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Steve,

Not 100% sure. Maybe our implementation of something like this in DIPY can
help?

https://github.com/nipy/dipy/blob/master/dipy/io/utils.py#L49-L91

Cheers,

Ariel



On Tue, Apr 23, 2019 at 7:24 AM Stephen Taylor <stephen.taylor at imm.ox.ac.uk>
wrote:

> Hi,
>
>
>
> I don't understand how to set RGB values directly in NiBabel. I have seen
> the previous post (
> https://mail.python.org/pipermail/neuroimaging/2016-November/001230.html)
> that gives random colours in a 3d matrix but I don't understand how to
> assign a specific RGB value in a particular voxel.
>
>
>
> So building on the previous example in the link, I create a 2 x 1 x 1
> volume and change the values of the colours directly:
>
>
>
> import nibabel as nib
>
> import numpy as np
>
> nifti_path = "test.nii"
>
>
>
> shape_3d = (2,1,1)
>
> rgb_dtype = np.dtype([('R', 'u1'), ('G', 'u1'), ('B', 'u1')])
>
> rgb_arr = np.random.randint(0, 256, size=shape_3d + (3,)).astype('u1')
>
> rgb_arr[0][0][0] = [100,150,200]
>
> rgb_arr[1][0][0] = [10,20,30]
>
>
>
> rgb_typed = rgb_arr.copy().view(rgb_dtype).reshape(shape_3d)
>
>
>
> img = nib.Nifti1Image(rgb_typed, np.eye(4))
>
> print(rgb_typed)
>
> nib.save(img, nifti_path)
>
>
>
> The image that is returned (?test.nii?) when inspected in Fiji/ImageJ
> looks like this:
>
>
>
> [image: image.png]
>
>
>
> and the  rgb_typed  array is:
>
>
>
> [[[(100, 150, 200)]]
>
>
>
>  [[( 10,  20,  30)]]]
>
>
>
> However, in the actual image (shown above) the green colour RGB values are
> 100,200,020 (not as I expected 100,150,200)and the red colour is
> 150,010,030 (not as I expected 10,20,30) so the RGB values seem to be
> mixed up. Clearly I am doing something wrong. How do I directly set the
> colours of a voxel in a volume?
>
>
>
> Thanks, for any help,
>
>
>
> Steve
>
> ----------------------------------
>
> Head of Analysis, Visualisation  and Informatics,
>
> MRC Weatherall Institute of Molecular Medicine,
>
> Oxford.
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20190424/1bf95aef/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 1550 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20190424/1bf95aef/attachment-0001.png>

------------------------------

Message: 2
Date: Thu, 25 Apr 2019 00:04:00 -0400
From: Dalton Sakthivadivel <dalton.sakthi at gmail.com>
To: neuroimaging at python.org
Subject: [Neuroimaging] OrthoSlicer3D
Message-ID: <9D9654D6-F2E5-4F71-8922-F4656316C656 at gmail.com>
Content-Type: text/plain;       charset=utf-8

Dear nipy team,

Can you describe to me some of the limitations on function that OrthoSlicer3D has? Is it limited to accepting images that are of the brain, or arrays of a certain size?

OrthoSlicer3D does not work for my data and I can?t make heads nor tails of it. Rather than a typical output, it plots four black squares, as though I hadn?t put any data in at all. It may be an issue that my .nii file contains images which are not of the human brain. Otherwise I am at a loss. I can attach my code to this email at a later time.

I would very much appreciate any help you had to give in this matter, including alternative suggestions for displaying typical 4D nifti images contained in .nii files.

Thank you,

Dalton Sakthivadivel

------------------------------

Message: 3
Date: Thu, 25 Apr 2019 12:23:13 +0000
From: Christopher Markiewicz <markiewicz at stanford.edu>
To: Neuroimaging analysis in Python <neuroimaging at python.org>
Subject: Re: [Neuroimaging] OrthoSlicer3D
Message-ID:
        <BN6PR02MB2675780631DC6497B058F980A93D0 at BN6PR02MB2675.namprd02.prod.outlook.com>

Content-Type: text/plain; charset="windows-1252"

Hi Dalton,

Without seeing the file or a screenshot, my best guess is that your affine matrix indicates the "center" of the image is in a corner and that the edges of the image are empty. Try clicking in the middle of each square to select different voxels. If there is content in the middle of your image, selecting a voxel in the center should reveal it.

If you're calling `OrthoSlicer3D` directly, then your origin will be at (i, j, k) = (0, 0, 0), which will cause the situation I describe above. It will also treat your voxels as isotropic 1mm, which may not be correct. For NIfTI and other volumetric files, I would recommend the alternative `img.orthoview()`, which will pass the correct affine matrix by default.

Also a quick note that OrthoSlicer3D doesn't work well on OSX. That may be another source of problems.

Chris
________________________________
From: Neuroimaging <neuroimaging-bounces+markiewicz=stanford.edu at python.org> on behalf of Dalton Sakthivadivel <dalton.sakthi at gmail.com>
Sent: Thursday, April 25, 2019 12:04 AM
To: neuroimaging at python.org
Subject: [Neuroimaging] OrthoSlicer3D

Dear nipy team,

Can you describe to me some of the limitations on function that OrthoSlicer3D has? Is it limited to accepting images that are of the brain, or arrays of a certain size?

OrthoSlicer3D does not work for my data and I can?t make heads nor tails of it. Rather than a typical output, it plots four black squares, as though I hadn?t put any data in at all. It may be an issue that my .nii file contains images which are not of the human brain. Otherwise I am at a loss. I can attach my code to this email at a later time.

I would very much appreciate any help you had to give in this matter, including alternative suggestions for displaying typical 4D nifti images contained in .nii files.

Thank you,

Dalton Sakthivadivel
_______________________________________________
Neuroimaging mailing list
Neuroimaging at python.org
https://mail.python.org/mailman/listinfo/neuroimaging
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20190425/ea154742/attachment-0001.html>

------------------------------

Message: 4
Date: Thu, 25 Apr 2019 10:35:32 -0400
From: Dalton Sakthivadivel <dalton.sakthi at gmail.com>
To: neuroimaging at python.org
Subject: Re: [Neuroimaging] OrthoSlicer3D
Message-ID: <878B56B5-8049-40BF-9E33-FE0CA2CE7ECE at gmail.com>
Content-Type: text/plain; charset=us-ascii

Thank you for your feedback. I will try out orthoview() as a viewer.


------------------------------

Subject: Digest Footer

_______________________________________________
Neuroimaging mailing list
Neuroimaging at python.org
https://mail.python.org/mailman/listinfo/neuroimaging


------------------------------

End of Neuroimaging Digest, Vol 47, Issue 8
*******************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20190430/b82bc731/attachment.html>


More information about the Neuroimaging mailing list