def parse_vge(header): """Parse vge header file""" file_section = header.get('VolumeSection0\\_FileSection0') image_size_string = file_section['filesize'] image_size = [int(i) for i in image_size_string.split()] volume_section = header.get('VolumeSection0') voxel_size_string = volume_section['volumeresolution'] voxel_size = [float(i) for i in voxel_size_string.split()] file_format = file_section['filefileformat'] if file_format != "VolumeFileFormat_Raw": raise ValueError("Unknown file format " + file_format) msb = True # True file_format = FileFormats.VOL_FORMAT dim_order = dim_order_from_header(header) data_type = DataType.name_from_vge(file_section['filedatatype']) compression = None header_dict = header return (FileImageDescriptor(file_format=file_format, dim_order=dim_order, data_type=data_type, image_size=image_size, msb=msb, compression=compression, voxel_size=voxel_size), header_dict)
def parse_mhd(header): """Read a metaheader and returns a FileImageDescriptor""" file_format = "mhd" dim_order = get_dim_order(header) data_type = DataType.name_from_metaio(header["ElementType"]) image_size = header["DimSize"] msb = header["BinaryDataByteOrderMSB"] compression = None return (FileImageDescriptor(file_format=file_format, dim_order=dim_order, data_type=data_type, image_size=image_size, msb=msb, compression=compression), header)
def create_write_file(cls, subimage_descriptor, file_handle_factory): """Create a MetaIoFile class for this filename and template""" header_template = cls._create_meta_header(subimage_descriptor) # header_template = copy.deepcopy(subimage_descriptor.template) local_file_size = subimage_descriptor.get_local_size() local_origin = subimage_descriptor.get_local_origin() if subimage_descriptor.data_type: header_template["ElementType"] = \ DataType.metaio_from_name(subimage_descriptor.data_type) header_template["DimSize"] = local_file_size header_template["Origin"] = local_origin filename = subimage_descriptor.filename return cls(local_file_size, filename, file_handle_factory, header_template)
def _create_meta_header(cls, subimage_descriptor): local_file_size = subimage_descriptor.get_local_size() local_origin = subimage_descriptor.get_local_origin() local_voxel_size = subimage_descriptor.get_local_voxel_size() transform_matrix = condensed_to_cosine( subimage_descriptor.axis.to_condensed_format()) header = get_default_metadata() header["ObjectType"] = 'Image' header["NDims"] = np.size(local_file_size) header["BinaryData"] = 'True' header["BinaryDataByteOrderMSB"] = subimage_descriptor.msb header["CompressedData"] = 'False' header["TransformMatrix"] = transform_matrix header["ElementSize"] = local_voxel_size header["DimSize"] = local_file_size header["ElementType"] = \ DataType.metaio_from_name(subimage_descriptor.data_type) header["Origin"] = local_origin return header
def test_metaio_from_name(self): self.assertEqual(DataType.metaio_from_name("short"), "MET_SHORT")
def test_name_from_metaio(self): self.assertEqual(DataType.name_from_metaio("MET_SHORT"), "short")