예제 #1
0
파일: ogr.py 프로젝트: stoianmihail/OGR
def preprocessing(pixels):
	print "-------------Preprocessing phase--------------"
	
	#Gaussian filter
	print "Passing gaussian filter."
	pixels = filters.gaussian(pixels)

	#define threshold to binarization of image
	k = util.otsu_thresholding(pixels)
	print "Threshold used in the binarization: %d" % (k)
	#binarize image using the threshold k
	print "Getting binarized image."
	pixels = util.binarization(pixels, k)

	print "Closing operator."
	pixels = morphology.binary_closing(pixels)
	print "Opening operator."
	pixels = morphology.binary_opening(pixels)

	return pixels
예제 #2
0
def gray2otsu(gray_im, verbose=1):
    ''' Otsu thresholding '''
    otsu_im, o_th = otsu_thresholding(gray_im)
    if verbose:
        print 'Otsu threshold: ', o_th
    return otsu_im
예제 #3
0
def gray2otsu(gray_im, verbose=1):
    ''' Otsu thresholding '''
    otsu_im, o_th = otsu_thresholding(gray_im)
    if verbose:
        logger.info('Otsu threshold: {}'.format(o_th))
    return otsu_im
예제 #4
0
    slide.level_dimensions[slide_level])
#center of slide
c_x, c_y = center_of_slide_level(slide, slide_level)
print "center of x : {0} , center of y : {0}".format(c_x, c_y)

#slide padding size
padding = 10
#read_region
tile_0255 = slide.read_region((0, 0), slide_level, (s_level_w, s_level_h))
im_rgba = np.array(tile_0255)

#convert to gray from rgba
im_gray = cv2.cvtColor(im_rgba, cv2.COLOR_RGBA2GRAY)
im_rgb = cv2.cvtColor(im_rgba, cv2.COLOR_RGBA2RGB)
#apply atsu thresholding
im_gray_ostu, x = otsu_thresholding(im_gray)
temp = im_gray
#cv2.drawContours(im_gray,im_gray_ostu,-1,255,-1)
#cv2.findContours(im_gray,)
print "ostu image  max value : {0}".format(np.max(im_gray_ostu))
print "otsu threaholding :{0}\n".format(x)
#image_labels = measure.label(im_gray_ostu)
print "image_labels \n"
print "gray image shape:", im_gray.shape

#apply mopology
kernel = np.ones((2, 2), np.uint8)
kernel_1 = np.ones((5, 5), np.uint8)
opening = cv2.morphologyEx(im_gray_ostu, cv2.MORPH_OPEN, kernel)
opening_1 = cv2.morphologyEx(im_gray_ostu, cv2.MORPH_OPEN, kernel_1)
closing = cv2.morphologyEx(im_gray_ostu, cv2.MORPH_CLOSE, kernel)
예제 #5
0
print "WSI Dimensions (width , hight) : {0}".format(slide.dimensions)
"""Slide.read reagion"""

slide_level = 3
rgba_im = slide.read_region((0, 0), slide_level,
                            slide.level_dimensions[slide_level])
rgba_im = np.array(rgba_im)

rgb_im = cv2.cvtColor(rgba_im, cv2.COLOR_RGBA2RGB)
"""Slide image convert to gray"""

gray_im = cv2.cvtColor(rgb_im, cv2.COLOR_RGB2GRAY)
"""Slide image apply atsu thresholding"""

otsu_im, o_th = otsu_thresholding(gray_im)
"""Slide image Draw Contours"""
#cont_im = rgb_im
#cv2.drawContours(cont_im,otsu_im,-1,(0,255,0),-1)
"""mopology """

kernel_o = np.ones((5, 5), np.uint8)
#kernel_c = np.ones((1,1),np.uint8)
morp_im = cv2.morphologyEx(otsu_im, cv2.MORPH_OPEN, kernel_o)
#morp_im = cv2.morphologyEx(otsu_im,cv2.MORPH_CLOSE,kernel_c)

print morp_im.shape

morp_im = morp_im == 0
morp_im = (morp_im).astype(float)
"""patch size,leveled patch size """