Dear Andras
Thanks a lot for your guidance. At now, I can center my sphere model in the voxel with maximum uptake. As mentioned you, firstly I changed indices array (indicesKJI, coordinates position of maximum uptake) from (K J I) to (I J K). After doing it, I calculate inverse matrix volumeRasToIjk with the name of volumeIjkToRas. Finally I applied volumeIjkToRas to indicesIJK.
Code written for doing it:
#Load PET images with "DICOM" module
#Rename PET node in "Data" to PETnode
#Click on "Center Volume" in "Volumes" node
PETnode = slicer.util.getNode('PETnode')
PETnumpy = slicer.util.arrayFromVolume(PETnode)
#PETnumpy.max()
import numpy as np
indicesKJI = np.where(PETnumpy == PETnumpy.max())
indicesIJK = [indicesKJI[2], indicesKJI[1], indicesKJI[0]]
indicesIJK = np.append(indicesIJK,1)
volumeNode = getNode('PETnode')
volumeRasToIjk = vtk.vtkMatrix4x4()
volumeNode.GetRASToIJKMatrix(volumeRasToIjk)
import numpy as np
from numpy.linalg import inv
volumeRasToIjk = np.array([[volumeRasToIjk.GetElement(0,0), volumeRasToIjk.GetElement(0,1), volumeRasToIjk.GetElement(0,2), volumeRasToIjk.GetElement(0,3)],[volumeRasToIjk.GetElement(1,0), volumeRasToIjk.GetElement(1,1), volumeRasToIjk.GetElement(1,2), volumeRasToIjk.GetElement(1,3)],[volumeRasToIjk.GetElement(2,0), volumeRasToIjk.GetElement(2,1), volumeRasToIjk.GetElement(2,2), volumeRasToIjk.GetElement(2,3)],[volumeRasToIjk.GetElement(3,0), volumeRasToIjk.GetElement(3,1), volumeRasToIjk.GetElement(3,2), volumeRasToIjk.GetElement(3,3)]])
volumeIjkToRas = inv(volumeRasToIjk)
indicesRAS = np.dot(volumeIjkToRas, indicesIJK)
sphere = vtk.vtkSphereSource()
sphere.SetRadius(10.)
sphere.SetCenter(indicesRAS[0], indicesRAS[1], indicesRAS[2])
sphere.SetPhiResolution(30)
sphere.SetThetaResolution(30)
modelsLogic = slicer.modules.models.logic()
model = modelsLogic.AddModel(sphere.GetOutput())
model.GetDisplayNode().SetSliceIntersectionVisibility(True)
model.GetDisplayNode().SetSliceIntersectionThickness(3)
model.GetDisplayNode().SetColor(1,0,0)
sphere.Update()
Screenshot result: