help > Converting .swc file to matlab matrix
Showing 1-9 of 9 posts
Display:
Results per page:
Nov 19, 2016  01:11 PM | Shubham Sharma - IIT Ropar
Converting .swc file to matlab matrix
How can one convert a .swc file to a matlab matrix?
Nov 20, 2016  02:11 AM | Hanchuan Peng
RE: Converting .swc file to matlab matrix
It is a very simple txt format, each row is id, type, x,y,z, radius, and parent id.

You can find a lot of information at vaa3d github wiki about the format as well.

You may also use the Vaa3D's Matlab IO toolbox to load the swc files into Matlab data structures.

Originally posted by Shubham Sharma:
How can one convert a .swc file to a matlab matrix?
Nov 20, 2016  03:11 AM | Shubham Sharma - IIT Ropar
RE: Converting .swc file to matlab matrix
Originally posted by Hanchuan Peng:
It is a very simple txt format, each row is id, type, x,y,z, radius, and parent id.

You can find a lot of information at vaa3d github wiki about the format as well.

You may also use the Vaa3D's Matlab IO toolbox to load the swc files into Matlab data structures.

Originally posted by Shubham Sharma:
How can one convert a .swc file to a matlab matrix?
Dear Sir
Thank you for your reply. But the load_v3d_swc_file function in the Vaa3D Matlab IO toolbox returns a matrix which replicates the original data of the .swc file only. For example, if the original .swc file has the following data:

[color=#000000]# generated by Vaa3D Plugin sort_neuron_swc
# source file(s): /local3/BigNeuron_gt/Cambridge_ManualPeter_in_vitro_confocal_GFP_human/Image4/Image4.swc
# id,type,x,y,z,r,pid
1 18 263.75 371.25 11 8 -1
2 18 260.972 371.25 11 7 1
3 18 258.75 371.25 11 7 2
4 46 256.25 371.25 12 6 3
[/color]

then the function will return a matrix which is of the form:
B =
[[1, 18, 263.75, 371.25 11, 8 ,-1],
 [2, 18, 260.972, 371.25, 11, 7, 1],
 [3, 18, 258.75, 371.25, 11, 7, 2],
 [4, 46, 256.25, 371.25, 12, 6, 3]]

But that is not what is required. We need a 3D matrix lets say A, each of whose (x,y,z) element represents the intensity value ie A(x,y,z) at that point whose coordinates are x,y,z. However, the matrix returned by the function load_v3d_swc_file will still have the data in the form of radius as it was before.

We also tried to write an algorithm to convert B matrix's data into the form required by us. But the quality of the images was not good. What we did was - we marked the intensity of all the pixels around the particular x,y,z coordinate within the radius r as 1 and rest as 0 for each row of .swc file. This gave images whose quality was quite bad. I hope I have made my problem clear. Please suggest a solution.
Nov 20, 2016  04:11 AM | Hanbo Chen - the university of georgia
RE: Converting .swc file to matlab matrix
I think what you are asking for is to generate an image from swc file. Please be aware that swc file itself is not an image file.

You can try following vaa3d plugin to generate a mask image from swc file:

neuron_utilities=>swc_to_maskimage_cynlinder_unit

After that, you can use vaa3d matlab image IO or other image reading functions to load the image into matlab

Hanbo
Nov 20, 2016  02:11 PM | Shubham Sharma - IIT Ropar
RE: Converting .swc file to matlab matrix
Thank you very much Sir. Your answer was of great help.
Nov 23, 2016  08:11 AM | Shubham Sharma - IIT Ropar
RE: Converting .swc file to matlab matrix
Dear Sir
I used neuron_utilities->swc_to_maskimage_cylinder_unit and then used data_IO plugin to obtain Z slices of the masked image.

But the number of slices I got for the original .v3dpbd image and the number of slices I got for .swc image are not the same. For example,  in p_checked6_human_allen_confocal inside gold166 folder, it got 85 slices for the original image and 137 slices for the reconstructed image.


Also, when I opened the slices of the reconstructed .swc file in Matlab, the clarity was even poorer than that of the .v3dpbd image. Please have a look at the screenshots which I am attaching for some of the planes of the raw and reconstructed image.




First image is the raw slice of the neuron and the second slice is the reconstructed image's slice. Also the sizes of the images obtained by data_IO plugin and thereafter using matlab_io function called load_v3d_raw_img_file differ in dimensions.

Please account for these discrepancies.
Attachment: 11R.bmp
Nov 23, 2016  08:11 AM | Shubham Sharma - IIT Ropar
RE: Converting .swc file to matlab matrix
This is the second reconstructed image.
Attachment: 11SWC.bmp
Nov 23, 2016  12:11 PM | bsuter - IST Austria
RE: Converting .swc file to matlab matrix
Dear Shubham,
When you have SWC in Matlab and if you wish to generate a 3D matrix
with intensity values, what should these intensity values represent?

In the original image the intensity represents the imaged fluorophore.
After reconstruction, if you want the intensity to be proportional to
dendritic length (or dendritic surface area) in each voxel, please
feel free to use the Matlab source code attached to
the following paper (Source code DOI:
http://dx.doi.org/10.7554/eLife.05422.01...). This is *not* a Vaa3D
plugin, nor is it related to this project, but perhaps it fills a
particular need of yours (and others), so I hope you won't mind me
mentioning it here.

Yamawaki, N., K. Borges, B. A. Suter, K. D. Harris, and G. M. G.
Shepherd (2015, January). A genuine layer 4 in motor cortex with
prototypical synaptic circuit connectivity. eLife 3, e05422+.

Nov 27, 2016  10:11 AM | Shubham Sharma - IIT Ropar
RE: Converting .swc file to matlab matrix
Dear Ben Suter
I tried the function swcPlot3Dt with the following arguments
  • swcData ie an N*7 array of SWC-format reconstruction
  • newFig whose value was set to 1
However, the figure which got plotted did not show anything. Please suggest what went wrong.

Also, the two images were uploaded to convey that the original image's slice or the raw image's slice looks much clean and crisp than the manually reconstructed image's slice. Plus, the dimensions of the reconstructed image as it is obtained from the Vaa3d plugin do not match with those of the raw/original image obtained from Vaa3D.

Please suggest what went wrong.