Skip to content

Instantly share code, notes, and snippets.

@DreamOneYou
DreamOneYou / pinjie.py
Created July 16, 2021 14:48
对图像进行分割
import math
import torch
import numpy as np
def split_image(img, crop_size=(128,128,128)):
patient_image = img # (1, 240, 240, 155, 4)
patient_image = patient_image[0, ...] # (240, 240, 155, 4)
patient_image = patient_image.permute(3, 0, 1, 2) # (1, 4, 155, 240, 240)
patient_image = patient_image.cpu().numpy()
pasient_image = crop_pad(patient_image, crop_size)
patient_image = torch.from_numpy(pasient_image).permute(1, 0, 2, 3, 4) # (C, S, T, Y, W)