Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic code for fcsv reader #2

Open
wants to merge 1 commit into
base: landmark_app_20190405
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions niftynet/contrib/fcsv_reader/0001_27588.fcsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#Fiducial List file /Shared/sinapse/CACHE/20160520_PREDICTHD_long_CACHE/singleSession_0001_27588/LandmarkInitialize/BCD/BCD_ACPC_Landmarks.fcsv
#numPoints = 51
#symbolScale = 5
#visibility = 1
#textScale = 4.5
#color = 0.4,1,1
#selectedColor = 1,0.5,0.5
#label,x,y,z,sel,vis
AC,0.022481131635158524,-0.03241262513099352,0.09632827194379834,1,1
BPons,1.8645660536814521,-28.501591695014845,-35.49375715884035,1,1
CM,-0.1028433173519987,-17.642400076852653,-2.0585982670143674,1,1
LE,-27.641465753788214,47.75605605907536,-21.70617976413726,1,1
PC,-0.2108937917773761,-27.104980286166697,-0.1350388791656596,1,1
RE,30.559804523104255,48.13686574145882,-20.777926893461615,1,1
RP,0.13298449434801518,-23.344233553271124,-12.918515104144294,1,1
RP_front,-0.24335804895573276,-34.74426147003849,-18.010587594162608,1,1
SMV,0.2901110429337945,-39.01916051821165,-16.479360968313156,1,1
VN4,1.2135580596967876,-48.61438937833321,-25.39944497043434,1,1
callosum_left,-23.375289609464307,-55.032609759616484,11.91376001508971,1,1
callosum_right,26.024619245872778,-49.85979642522741,13.384298874091428,1,1
dens_axis,-0.8785573145930912,-27.72734874384416,-66.43535070699247,1,1
genu,-0.19267442277729407,16.852151782196323,9.601355986645792,1,1
l_caud_head,-14.826197445878034,14.969179678294092,6.621049135823253,1,1
l_corp,-29.41408681040191,-48.08223522160287,-35.84205560284369,1,1
l_front_pole,-10.43080329908726,53.17084799531153,28.029902923214014,1,1
l_inner_corpus,-1.577055722348477,-18.73735188137699,21.111148623406653,1,1
l_lat_ext,-61.33259693564417,-40.82308140324586,-4.190516289985421,1,1
l_occ_pole,-8.935637969528843,-102.65878573571989,-5.837500696266878,1,1
l_prim_ext,-29.229301824503622,-41.177713640738396,-24.48296961332181,1,1
l_sup_ext,-16.78424200280258,-27.884110195471298,64.88238176551914,1,1
l_temp_pole,-35.32176500340664,20.234703805307532,-20.679701169791695,1,1
lat_left,-19.569717830135655,-13.826314317041977,-11.93342179066418,1,1
lat_right,21.750967645794635,-12.62486750210986,-12.367617913060382,1,1
lat_ven_left,-31.83448634749371,-14.58677502396956,-14.590460937133567,1,1
lat_ven_right,31.013344442138603,-9.716829769729676,-16.036374148067793,1,1
left_cereb,-10.160748762541349,-38.73963194154938,-23.529387845641356,1,1
left_lateral_inner_ear,-56.986813502594565,-8.999555826614252,-41.7096273934753,1,1
m_ax_inf,0.12493164264197165,-48.06859796822409,12.876122467230502,1,1
m_ax_sup,-0.7682506235437605,6.482718224432941,23.69425242882713,1,1
mid_basel,-0.6797813996851534,-11.600530018222955,4.892343363773401,1,1
mid_lat,-0.01344360923866994,-15.238393913447926,-5.3850638051877056,1,1
mid_prim_inf,0.6582819816529446,-51.7019178660373,-24.701056882328267,1,1
mid_prim_sup,0.30715640203901096,-65.72438089175131,-9.043731532799985,1,1
mid_sup,1.0800576878867028,-54.73129768596024,0.24973618073585424,1,1
optic_chiasm,0.284033040506682,1.0770896767813656,-11.15200025335908,1,1
r_caud_head,15.32366873166477,17.418398352162686,10.282282403432571,1,1
r_corp,28.065716932173196,-50.09742199619871,-35.8863924372445,1,1
r_front_pole,9.282228865905484,53.64385773889343,20.359360383362517,1,1
r_inner_corpus,0.3750664579883489,-18.621152492598828,20.04736016346814,1,1
r_lat_ext,64.47685718089897,-31.456099309079985,-2.461208210665723,1,1
r_occ_pole,18.026380089890477,-99.6971135427791,-7.188458824309168,1,1
r_prim_ext,29.15692350632211,-37.323391086051096,-24.200298244358343,1,1
r_sup_ext,7.062978169625272,-48.83078907071558,65.034736105428,1,1
r_temp_pole,35.8308982781247,22.221251648850576,-20.059697985669054,1,1
right_lateral_inner_ear,56.76557582293636,-10.852806094401668,-40.41078579756389,1,1
rostrum,-0.10670269028927093,8.1435166054155,5.593083428764335,1,1
rostrum_front,-0.16282452013595305,3.8353646742608043,17.37306179154106,1,1
top_left,-21.019253567118948,27.911579557467853,47.07503850272812,1,1
top_right,23.330261595397282,29.540558871893314,43.72661749307131,1,1
36 changes: 36 additions & 0 deletions niftynet/contrib/fcsv_reader/fcsv_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
import pandas as pd
from niftynet.layer.base_layer import Layer


class FCSVReader(Layer):
def __init__(self, name="fcsv_reader"):
self.fid_pts = None
super(FCSVReader, self).__init__(name=name)

def initialise(self, path_to_fcsv, fiducials=["RE"]):
"""
Assuming that the input file format is label,x,y,z,sel,vis
:param path_to_fcsv:
:param fiducials:
:return:
"""
df = pd.read_csv(
path_to_fcsv,
header=None,
comment="#",
names=["fiducial_labels", "xcoord", "ycoord", "zcoord", "sel", "vis"],
)
self.fid_pts = {}
for fid in fiducials:
fid_df = df[df["fiducial_labels"] == fid]
# the sign flipping in x and y is to convert RAS(used by slicer) to LPS(used in DICOM and itk)
xcoord = -1 * fid_df["xcoord"].values.reshape(-1, 1)
ycoord = -1 * fid_df["ycoord"].values.reshape(-1, 1)
zcoord = fid_df["zcoord"].values.reshape(-1, 1)
one_d_vec = np.concatenate((xcoord, ycoord, zcoord), axis=1).reshape(-1, 1)
self.fid_pts[fid] = one_d_vec
return self

def layer_op(self, fid="RE"):
return self.fid_pts[fid]
8 changes: 8 additions & 0 deletions niftynet/contrib/fcsv_reader/test_fcsv_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from fcsv_reader import *

my_fcsv_reader = FCSVReader()
my_fcsv_reader = my_fcsv_reader.initialise(
path_to_fcsv="0001_27588.fcsv", fiducials=["LE", "RE"]
)
print(my_fcsv_reader.layer_op())
print(my_fcsv_reader.layer_op(fid="LE"))