Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
0
def get_local_feature_one_vertebra(v, I, label, block_size=block_size):
    # step 1: filter the image. 
    # step 2: extract 1st - 4th order of the filtered image.
    # here we use, 6 different scaled gaussian + linear transformation
    # (DCT, DST, fft)
    slice_num = I.shape[0]
    width = I.shape[2]
    height = I.shape[1]
    
    
    feature_dim = get_feature_dim()
    feature = np.empty((slice_num,  height, width, feature_dim), dtype=np.float)
    
    # first guassian filtered
    prev_filtered_dim = 0
    for s in sigmas:
        print "sigma value: " + str(s)
        filtered_dim = get_filtered_dim(s)
        for i in range(I.shape[0]):
            print "for slice " + str(i)
            img = I[i]
            f = get_local_feature_one_vertebra_one_slice_one_sigma(img, s)
            feature[i, :, :, prev_filtered_dim*moment: (prev_filtered_dim + filtered_dim)*moment]=f
        prev_filtered_dim = filtered_dim
            
    # step 3: now that we have feature of all the points in image scale,
    # we can extract the feature for all the sample points. 
    # Based on the paper, IEEE T. on Medical Imaging, 2002, "ASM Segmentation with optimal feature"
    # we need to use 5*5 window centered at each landmark.
    # note: feature = np.empty((slice_num,  height, width, feature_dim),dtype=np.float)
            
    print "start " + str( block_size)+ "x" + str(block_size) + " sampling..."
    block_area = block_size*block_size
    feature_block = np.empty((8, slice_num*block_area, feature_dim), dtype=np.float)
    label_block = np.empty((8, slice_num*block_area), dtype=np.int)
    
    size_1 = block_size/2
    size_2 = block_size - size_1
    
    for i in range(8): 
        idx_x = i*2 
        idx_y = i*2 + 1
        # slice_num * 2k+1 * feature_dim
        for n in range(slice_num):
            # here block is  block centered at landmark
            min_x = v[n, idx_x] - size_1
            max_x = v[n, idx_x] + size_2
            min_y = v[n, idx_y] - size_1
            max_y = v[n, idx_y] + size_2
            
            #########################################################
            #DEBUG
            if n == 0:
                from src.util import show_slice
                from src.util import read_jpg, crop_slice
                pn = 1
                fn = '4'
                fn =  '/Users/ruhansa/Dropbox/spine/data/p' + str(pn) + '/label/'+ fn + '.jpg'
                label_jpg = read_jpg(fn)
                label_arr = np.array(label_jpg.convert('L'), dtype=np.int16)
                x_min = 0
                x_max = 512
                y_min = 130
                y_max = 350
                clabel = crop_slice(label_arr, (x_min, y_min), (x_max, y_max)) * 255
                clabel[min_x: max_x, min_y: max_y] = 255
                show_slice(clabel)
            #########################################################
                
            
            feature_block[i, n*block_area:n*block_area+block_area, :] = feature[n, min_x:max_x, min_y: max_y, : ].reshape(block_area, feature_dim)
            label_block[i, n*block_area: n*block_area+block_area] = label[n, min_x:max_x, min_y:max_y].reshape(block_area)
            
    
    return label_block, feature_block
Esempio n. 5
0
fn = '/Users/ruhansa/Desktop/ex.jpg'
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)
Esempio n. 6
0
# 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))