I’m using pyigtl to create a server to send color images to Slicer via IGT Link.
I can successfully receive the images in Slicer creating a client using the OpenIGTLinkIF module.
However I cannot show the received images as color RGB images but I can only show them as 3 separate channels (R, G and B).
Can you please tell me how to show the image as a color image?
A volume node is created automatically when the first image is received. For single-component images a vtkMRMLScalarVolumeNode is created, while for multi-component images (such as an RGB color image) a vtkMRMLVectorVolumeNode is created. The class of an object cannot be changed, therefore you may end up having a scalar volume node storing multi-component image data if you first send a single-component volume and then a color volume using the same device.
If you need to send both grayscale and color volumes then you can avoid having suboptimal volume node type by using different device names (e.g., Image-BMode, Image-Doppler). Alternatively, you can implement a custom logic that observes the received image data and if it detects that the image data type is changed then delete and recreate the volume node.
It seems that the behaviour is not exactly the one you described.
This is my python code:
import pyigtl # pylint: disable=import-error
from time import sleep
import numpy as np
server = pyigtl.OpenIGTLinkServer(port=18944)
cap = cv2.VideoCapture(0)
if not server.is_connected():
# Wait for client to connect
ret,img = cap.read()
img = np.transpose(img, axes=(2, 1, 0))
print(img.shape) # it prints (3, 640, 480) so it is multi-component
# Send image
image_message = pyigtl.ImageMessage(img, device_name="Image")
If in Slicer I type:
a = slicer.util.getNode("Image")
I get this output: (MRMLCore.vtkMRMLScalarVolumeNode)000001F1864280A8
So it seems a vtkMRMLScalarVolumeNode is created instead of a vtkMRMLVectorVolumeNode