Hey, I am trying to use vtkSLCReader to red binary slc file but it complains that its unable to read magic number.
ERR| vtkSLCReader (0x7fee9e404720): Error reading file: binary.slcFailed to read magic number
2023-02-26 11:41:24.544 ( 0.006s) [ 2CC3F4] vtkSLCReader.cxx:235 ERR| vtkSLCReader (0x7fee9e404720): Error reading file: binary.slcFailed to read magic number
I was able to read the above file with the below python code but i am struggling with VTK libraries, can someone help?
import struct
CHUNK_SIZE = 16 # bytes
# Open the binary SLC file in read mode
with open("JR03698.slc", "rb") as binary_file:
# Open the ASCII SLC file in write mode
with open("ascii_file.slc", "w") as ascii_file:
while True:
# Read the binary data in chunks
binary_data = binary_file.read(CHUNK_SIZE)
if not binary_data:
break
length = len(binary_data)
print(f'length {length}')
# Unpack the binary data using the struct module
if len(binary_data) == 16:
x, y, z, intensity = struct.unpack("f"*4, binary_data)
# Write the x, y, z and intensity values to the ASCII file
ascii_file.write("{}\n".format(x, y, z, intensity))