Exemple #1
0
def save_one_slice(arr, filename,width=_width, height=_height):
    temp = np.zeros((height, width))
    x = arr[np.arange(0, 15, 2)]
    y = arr[np.arange(1, 16, 2)]
    temp [x, y] = 255
    from src.util import save_slice
    save_slice(temp, filename)
Exemple #2
0
def save_all_landmarks_one_slice(arr, filename,width=_width, height=_height):
    from src.util import save_slice
    temp = np.zeros((height, width))
    x = arr[:, :, np.arange(0, 15, 2)].reshape(-1, 1)
    y = arr[:, :, np.arange(1, 16, 2)].reshape(-1, 1)
    temp[x, y] = 255
    save_slice(temp, filename)
Exemple #3
0
def show_all_slices_one_slice(arr, width=_width, height=_height,save=False, filename=None):
    from src.util import show_slice, save_slice
    temp = np.zeros((height, width))
    x = arr[:, np.arange(0, 15, 2)].reshape(-1, 1)
    y = arr[:, np.arange(1, 16, 2)].reshape(-1, 1)
    temp[x, y] = 255
    show_slice(temp)
    if save == True:
        save_slice(temp, filename)
Exemple #4
0
def show_one_slice(arr, width=_width, height=_height, save=False, filename=None):
    from src.util import show_slice
    temp = np.zeros((height, width))
    x = arr[np.arange(0, 15, 2)]
    y = arr[np.arange(1, 16, 2)]
    temp[x, y] = 255
    show_slice(temp)
    if save == True:
        from src.util import save_slice
        save_slice(temp, filename)
Exemple #5
0
def show_all_landmarks_one_slice_one_vertebra(arr, width=_width, height=_height,save=False, folder=None, vn=None):
    
    from src.util import show_slice, save_slice
    temp = np.zeros((height, width))
    x = arr[:, np.arange(0, 15, 2)].reshape(-1, 1)
    y = arr[:, np.arange(1, 16, 2)].reshape(-1, 1)
    temp[x, y] = 255
    show_slice(temp)
    if save == True:
        if not os.path.exists(folder):
            os.makedirs(folder)
        filename = folder + vn + '.jpg'
        save_slice(temp, filename)
from src.util import read_jpg
img = read_jpg(fn)
data = np.array(img.convert('L'), dtype=np.int16)
#import numpy as np
#mask = np.zeros((patient_number, 512, 512), dtype = np.int16)
#idx = data > 240 # find dural sac
#mask[idx] = 255


#subtracting the low pass from original
from scipy import ndimage
npix = 3
gauss = ndimage.gaussian_filter(data, sigma=npix)

high_pass = data - gauss

idx = high_pass < 0
high_pass[idx] = 0

#from skimage.feature import canny
#
#canvas = np.zeros((50, 84), dtype=np.int16)
#canvas = np.array(canny(high_pass/255., sigma=3)*255, dtype=np.int16)
##canvas[i] = high_pass[i]


from src.util import show_slice, save_slice
show_slice(gauss)
fn = '/Users/ruhansa/Desktop/gauss.jpg'
save_slice(gauss, fn)
# data_dir = dir + '/data/p1/'
data_dir = "/Users/ruhansa/Dropbox/spine/data/"


data = {}
from src.utils.util import read_dicom

patient_num = 4
folder = data_dir + "p" + str(patient_num) + "/t2w/"
data = read_dicom(folder)

# from src.util import show_volume
# show_volume(data,data.shape[0])
import numpy as np

mask = np.zeros((512, 512), dtype=np.int16)
idx = data < 30
n = 7
mask[idx[n]] = 255

from src.util import save_slice

save_slice(mask, "/Users/ruhansa/Dropbox/spine/data/p" + str(patient_num) + "/label/" + str(n) + "_init.jpg")
save_slice(data[n], "/Users/ruhansa/Dropbox/spine/data/p" + str(patient_num) + "/label/" + str(n) + "_raw.jpg")
from src.util import show_slice

show_slice(mask)
show_slice(data[n])
# from skimage.filter import canny
# show_slice(canny(data[n], 10))