def show_one_vertebra(arr, slice_number=_slice_num,width=_width, height=_height): from src.util import show_volume temp = np.zeros((slice_number, height, width)) for i in range(0, slice_number): x = arr[i, np.arange(0, 15, 2)] y = arr[i, np.arange(1, 16, 2)] temp[i, x, y] = 255 show_volume(temp, slice_number, show_line=False, point1_x=arr[:, 0], point1_y=arr[:, 1], point5_x=arr[:, 8], point5_y=arr[:, 9])
def show_all_landmarks(arr, slice_num=_slice_num,width=_width, height=_height): from src.util import show_volume temp = np.zeros((slice_num, height, width)) for j in range(0, slice_num): x = arr[:, j, np.arange(0, 15, 2)].reshape(-1, 1) y = arr[:, j, np.arange(1, 16, 2)].reshape(-1, 1) temp[j, x, y] = 255 show_volume(temp, slice_num, show_line=False)
data[i]=read_data(fn) #sumsum = 0 #num = 0 #for i in fnum: # idx = np.where(label_data[i].get_data() == 1) # num += np.array(idx[0]).size # sumsum += np.sum(data[i].get_data()[idx]) # #average = sumsum/num #================= get the location of the center ================== # goto slice 20 #slice_num = 20 #image = data[range_start].get_data()[slice_num] #label = label_data[range_start].get_data()[slice_num] #assumption made here is: upper bound of vertebrae is located nearly #at half of the body region, which is a non-black region #from src.util import show_slice #show_slice(image) #show_slice(label*255) #================================================================== from src.util import show_volume show_volume(data[15].get_data(),data[15].shape[0]) #sps = 5 #fn = result_dir + subject + '/' #landmarks = show_volume(label_data[range_start].get_data()*255, label_data[range_start].shape[0], slice_per_subject = sps, folder_name=fn)
# collecting data folder = "/Users/ruhansa/Dropbox/spine/data/" import numpy as np slice_num = 2 height = 512 width = 512 arr = np.zeros((slice_num, height, width), dtype=np.int16) for i in range(0, slice_num): dirname = folder + "p" + str(i) + "/label/" for file in os.listdir(dirname): if fnmatch.fnmatch(file, "*_bound.jpg"): slice_number = file.split("_")[0] filename = dirname + slice_number + ".jpg" from src.util import read_jpg r, g, b = read_jpg(filename).split() arr[i] = r from src.util import seperate_data import json f = open("/Users/ruhansa/Dropbox/spine/data/label.json", "r") diagnose = json.load(f) herniated, normal = seperate_data(diagnose, arr, vertebra_number=0, range_start=0, range_end=slice_num) landmarks = show_volume( herniated, herniated.shape[0], folder_name=folder + "label/", slice_per_subject=herniated.shape[0] )
from src.asm_util import get_raw_jpg_slices data = get_raw_jpg_slices() #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 = 5 gaussed = ndimage.gaussian_filter(data, sigma=npix) high_pass = data-gaussed idx = 0 > high_pass high_pass[idx] = 0 from skimage.feature import canny mask = np.zeros((512, 512), dtype=bool) mask[:, 200: 400]=1 canvas = np.zeros((patient_number, 512, 512), dtype=np.int16) for i in range(patient_number): canvas[i] = np.array(canny(high_pass[i]/255., sigma=3, mask=mask)*255, dtype=np.int16) #canvas[i] = high_pass[i] from src.util import show_volume show_volume(canvas, patient_number)
# -*- coding: utf-8 -*- """ Created on Mon Oct 12 11:08:35 2015 @author: Ruhan Sa This is a quick test to see if it's easy to extract the dural sac and vertebrae edge lines using proprocessing from MRI. Dural sac is with high intensity """ data_folder = 'C:\\Users\\Ruhan Sa\\Google Drive\\Raja_data\\Disc2\\DICOM\\PA000004\\ST000001\\SE000001\\' from src.util import read_dicom arr = read_dicom(data_folder) from src.util import show_volume show_volume(arr, arr.shape[0]) #from src.util import show_slice #show_slice(arr[6])