From 32ef4bbb0381f822c4df124595d401ad2f502c1b Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Fri, 5 Feb 2016 09:54:44 +0100 Subject: [PATCH] Script modification for testing. --- .../ma_autocount/plasmodium-autocount-0.1.py | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/Documentation/ma_autocount/plasmodium-autocount-0.1.py b/Documentation/ma_autocount/plasmodium-autocount-0.1.py index d97e059..14ae21d 100644 --- a/Documentation/ma_autocount/plasmodium-autocount-0.1.py +++ b/Documentation/ma_autocount/plasmodium-autocount-0.1.py @@ -58,7 +58,8 @@ N_processors = 1 # # What to show in diagnostic output images -Show_edges = True +Show_edges = False +Show_dark_stain = False Show_stain = False Show_infection = False @@ -93,9 +94,9 @@ Resize_height = 972 #512 # # gaussian_blur(image, a) - b * gaussian_blur(image, c) -Enhance_a = 1.0 -Enhance_b = 0.75 -Enhance_c = 20.0 +Enhance_a = 2.0 # base: 1.0, 50x: 2.0, 100x: 4.0 +Enhance_b = 0.75 # base: 0.75 +Enhance_c = 40.0 # base: 20.0, 50x: 40.0, 100x: 80.0 # Larger = enlarge background area, smaller = enlarge foreground area Background_weight = 0.915 #&median @@ -120,8 +121,8 @@ Infection_pixels_required = 1 # Cell size parameters # Size of cells, for Hough transform -Hough_min_radius = 5 -Hough_max_radius = 32 # 20 +Hough_min_radius = 20 # 50x: 20, 100x: 40 +Hough_max_radius = 45 # 50x: 45, 100x: 90 # Portion of cell used for classification as infected/weird # (may be abutting an infected cell, so be cautious) @@ -129,7 +130,7 @@ Hough_max_radius = 32 # 20 Cell_inside_radius = 0.9 # Do not allow another cell center to be detected within this radius -Cell_suppression_radius = 1.05 # 1.25 +Cell_suppression_radius = 0.8 # 1.05 # ======================= @@ -139,8 +140,8 @@ Cell_suppression_radius = 1.05 # 1.25 Max_dark_stain_proportion = 0.728 # Minimum/maximum radius (as determined by Hough transform) -Min_cell_radius = 11 # 9 -Max_cell_radius = 32 # 20 +Min_cell_radius = 25 # Base: 9, 50x: 25, 100x: 50 +Max_cell_radius = 40 # Base: 20, 50x: 40, 100x: 80 # Proportion of radius that center of mass can be away from Hough determined center Max_offcenter = 0.5 @@ -233,7 +234,7 @@ def gaussian_blur(array, amount): """ output = numpy.empty(array.shape, array.dtype) for i in xrange(array.shape[2]): - ndimage.gaussian_filter(array[:,:,i],amount,output=output[:,:,i]) + ndimage.gaussian_filter(array[:,:,i],amount, output=output[:,:,i]) return output @@ -272,6 +273,7 @@ def process(filename_in, filename_out, filename_coords, name): # Denoise/unsharp mask # [GB] (Concerne les trois channels RGB). a_enhanced = gaussian_blur(a, Enhance_a) - Enhance_b * gaussian_blur(a, Enhance_c) + # Split into foreground and background using k-medians status('fg/bg') @@ -323,8 +325,7 @@ def process(filename_in, filename_out, filename_coords, name): (a_enhanced[:,:,1] < color_fg[1]) & # [GB] Green channel fg ) - - + fg_float = fg.astype('float64') green = a[:,:,1] * fg_float green_local_bg = ndimage.gaussian_filter(green, Stain_bg_blur) @@ -350,6 +351,8 @@ def process(filename_in, filename_out, filename_coords, name): a_output[stain,2] += 128 if Show_infection: a_output[infection,0] += 128 + if Show_dark_stain: + a_output[infection,0] += 128 #a_output[stain, 1] += 128 @@ -409,7 +412,7 @@ def process(filename_in, filename_out, filename_coords, name): # (more blurring allows greater deviation from circularity) # (if you alter this you will also need to alter thresh, below) - hough = ndimage.gaussian_filter(hough, 1.0) + hough = ndimage.gaussian_filter(hough, 1.5) # 1.0 return hough @@ -426,15 +429,14 @@ def process(filename_in, filename_out, filename_coords, name): #a_output[:,:,:] = hough[:,:,None]*20 # Find and classify peaks in Hough transform image - thresh = 1.5 #Hmm + thresh = 0.8 #Hmm 1.5 candidates = [ ] for y in xrange(height): for x in xrange(width): if hough[y, x] > thresh: candidates.append((hough[y,x], y, x)) candidates.sort(reverse = True) - hough - + status('classify') @@ -568,6 +570,10 @@ def process(filename_in, filename_out, filename_coords, name): i2 = Image.fromarray(a_output.astype('uint8')) i2.save(filename_out) + thresh_output = numpy.clip(fg, 0, 255) + i3 = Image.fromarray(thresh_output.astype('uint8')) + i3.save(filename_out + " - thresholded.tiff") + def read_ac(filename): -- 2.43.0