def nodule_detect(nodules,j,numpyImage, numpyOrigin, numpySpacing):
#g = "input/subset"+str(k)+"/"+j
#numpyImage, numpyOrigin, numpySpacing = load_itk_image(j)
#jj = j.split("/")
#jj = jj[-1]
numpyImage = normalize(numpyImage)
print("Inside nodule-detect",numpyImage)
for i in range(len(nodules)):
vals = nodules.loc[i]
#print(j)
#print("In nodule-detect")
jj = j.split("/")
jj = jj[-1]
if(vals['seriesuid'] == (jj.replace(".mhd",""))):
print("Inside the nodule")
worldCoord = np.asarray([float(vals["coordX"]),float(vals["coordY"]),float(vals["coordZ"])])
print(worldCoord)
voxelCoord = worldToVoxelCoord(worldCoord, numpyOrigin, numpySpacing)
print(voxelCoord)
voxelCoord = voxelCoord
voxelWidth = 65
print("VoxelCoord :",voxelCoord[0])
print("Welcome")
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)]
patch = normalizePlanes(patch)
print (worldCoord)
print (voxelCoord)
print (patch)
outputDir = 'patches/'
plt.imshow(patch, cmap='gray')
plt.show()
#outputDir = 'patches/'
plt.savefig('patch'+".png")
Image.fromarray(patch*255).convert('L').save(os.path.join(outputDir,'patch_'+ str(worldCoord[0]) + '_' + str(worldCoord[1]) + '_' + str(worldCoord[2]) +'.tiff'))