Revision 27fa41066bf09a3c1ca00fd333f72755e481b16f authored by H.F on 13 April 2021, 10:57 UTC, committed by H.F on 13 April 2021, 10:57 UTC
1 parent f3455fe
splitcell.jl
using FileIO
using Images
using ImageSegmentation
using Statistics

"""
Use Laplace of Gaussian(LoG) filter extract cell from raw 3d image
Version Comment
0.1		initial
0.2		only LoG
"""

"""
Generate border form watershed result
"""
function watershedborder(watershed_segments)
marker_border = BitArray(undef, size(watershed_segments.image_indexmap));
marker_border .= false
for label in watershed_segments.segment_labels
marker_border .|= ((watershed_segments.image_indexmap.==label) .⊻ erode(watershed_segments.image_indexmap .==label));
end
marker_border;
end

"""
Use LoG fiter raw image to extract cell
"""
function split_cell_LoG(stack::Array{Gray{Normed{UInt16,16}},4};
LoG::Integer=40, thres = -1e-7)
println("Applying LoG(40) at Maximum Z Projection")
#img_edge = zeros(N0f16, 1900, 1300, time);
#mask_edge = zeros(Int16, 1900, 1300, time);
h, w, d, time = size(stack)
#local mask_markers = zeros(Bool, h, w, time);
local mask_markers = Array{Bool}(undef, h, w, time);
#@inbounds Threads.@threads for t in 1:time  #use 40 threads slow down speed. may due to gc time
@inbounds for t in 1:time  #use 40 threads slow down speed. may due to gc time
# remove possion noise with median filter on maximum z-project image
#local imgx = mapwindow(median!,
# maximum(view(stack, :, :, :, t), dims=3)[:,:,1], (5,5));
# LoG will blur image to low image struture under \sigma,
# So I remove median filter
local imgx = maximum(view(stack, :, :, :, t), dims=3)[:,:,1];
# extract intensity info with LoG
mask_markers[:,:,t] = imfilter(imgx, Kernel.LoG(LoG)) .< thres ;
#imgx_dist = distance_transform(feature_transform(imgx_log));
# filter markers for watershed
#imgx_markers = label_components( imgx_dist .> 50);
#imgx_segments = watershed( imfilter(1 .- imgx, Kernel.gaussian(9)), imgx_markers);
#img_edge[:,:,i] = .~watershedborder(imgx_segments).*imgx;
#mask_clear[:,:,i] = extract_nucleus( imgx, imgx_segments) .> 0;
#print("*");
end
println("Done")