0

I am trying to extract nodule patches from CT images based on the co-ordinates given in a CSV file. i keep getting this error msg at the worldcoord line :could not convert string to float(CordZ). I am not quite sure how to do that.

I have this so far:

def readCSV(filename):

    def readCSV(filename): lines = []
    with open(filename, 'r') as f:
        csvreader = csv.reader(f)
        for line in csvreader:
            lines.append(line)
    return lines

    cands = readCSV(cand_path)

    for cand in cands: 
        worldCoord = np.asarray([float(cand[3]),float(cand[2]),float(cand[1])])
        voxelCoord = worldToVoxelCoord(worldCoord, numpyOrigin, numpySpacing)
        voxelWidth = 65
        patch = numpyImage[voxelCoord[0],voxelCoord[1]-voxelWidth/2:voxelCoord[1]+voxelWidth/2,voxelCoord[2]-voxelWidth/2:voxelCoord[2]+voxelWidth/2]
        patch = normalizePlanes(patch)
        print ('data')
        print (worldCoord)
        print (voxelCoord)
jboockmann
  • 1,011
  • 2
  • 11
  • 27
  • Could you provide example data which you try to read? Are you sure that file does not contain header that you read as a normal data instead of skipping? – trivelt Aug 08 '17 at 07:14
  • Hi @jboockmann, i solved that error but i am getting new error at the patch line: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices – Anil Yadav Aug 08 '17 at 07:17
  • Then you should open a new question and close this one. – Jürg W. Spaak Aug 08 '17 at 07:21

2 Answers2

0

I additionally had to specify the line number for the CSV file. So Ii did:

for cand in cands[1:]
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
0

Solution for "only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices"

Change,

patch = numpyImage [voxelCoord[0],voxelCoord[1]- voxelWidth/2:voxelCoord[1]+voxelWidth/2,voxelCoord[2]-voxelWidth/2:voxelCoord[2]+voxelWidth/2]

to,

patch = numpyImage [int(voxelCoord[0]),int(voxelCoord[1])- int(voxelWidth/2):int(voxelCoord[1])+int(voxelWidth/2),int(voxelCoord[2])-int(voxelWidth/2):int(voxelCoord[2])+int(voxelWidth/2)]
user1410665
  • 719
  • 7
  • 23