Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
vsnnlab authored Jul 30, 2020
1 parent c29a710 commit 2cca0f7
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 345 deletions.
Binary file added AMaSiNe User Manual 07272020.pdf
Binary file not shown.
39 changes: 39 additions & 0 deletions STEP_0_Parameters.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%% 1. Image Directory
main_folder_dir='C:\Users\junhs\Downloads\AMaSiNe-master\AMaSiNe-with_Elastix_07162020';
cd(main_folder_dir);
addpath(genpath(main_folder_dir));

%% 2. Image names and slice order
img_format ='jpg'; % if tif = 'tif' ; jpg='jpg'
Slice_AP_orPA= 1; % If the brain is sliced from anterior to posterior, set this value = 1
% posterior to anterior, set this value = -1
slide_digit=3;
scene_digit=4;
channel_digit= 5;

%% 3. Anchor Image IDs for Angle Finding (for STEP_2 and 3)
anc_img_IDs= sort([1 4]);
img_IDs_reBoundary=[2];
threshold_scale = 1.5; %for step 3 only - increase this number if your slice boundary is smaller than what you expect;
%decrease this number if slice
%boundary is not clean enough.

%% 4. Image Parameters
xy_pix=0.653 * 2; % Pixel size = um/pixel
Name_Channels={'eGFP','DAPI'}; % In the right order
Color_Channel_Structure=2; % ID of Color Channel to be used for angle finding process
% DAPI or NISSL is very strongly recommended for
% the angle finding process (Step_4)
Structure_stain={'DAPI'}; % Choose one of the three : 'DAPI','AutoF','Nissl'
Color_Channel_Interest=[1]; % Color channel in which labelled cells are imaged (e.g. eGFP, tdTomato)

%% 5. Detection Parameters
soma_radius=[10 16]; % range of "radius" of labelled soma (in um) to be searched for

cell_det_thresh = 0.25; % Intensity difference between a cell and its background for a cell to be detected as a cell
% Lower this value, you'd get a better chance
% of detecting cells dim, but you also risk detecting noise as a cell

%% 6. Allen Atlas Info
size_vol = [528 320 456]; % Matrix size of the Allen 3D atlas
ref_atlas_vox_res=25; % Allen 3D Ref atlas : 1 voxel= 25um x 25um x 25um
4 changes: 2 additions & 2 deletions STEP_2_Anchor_Image_Selection.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
warning('off')
STEP_0_Parameters;
addpath(genpath(pwd))
img_name=Img_filename_list;

load('Step1_Outline_result.mat')
STEP_0_Parameters;

ref_resc=1/0.5;
downscaled_xy_pix=ref_atlas_vox_res*ref_resc;
Expand Down
1 change: 1 addition & 0 deletions STEP_3_Optional_Redraw_Slice_Boundary.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
clear all; clc;
addpath(genpath(pwd))
load('Step1_Outline_result.mat')
warning('off')
STEP_0_Parameters;
Expand Down
1 change: 1 addition & 0 deletions STEP_4_Angle_Finder.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
clear all; close all;
warning('off')
STEP_0_Parameters;
img_name=Img_filename_list;
Expand Down
69 changes: 38 additions & 31 deletions STEP_4to5_Cell_Detection.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
profile on
close all
clear all
close all; clear all
addpath(genpath(pwd));

warning('off')
STEP_0_Parameters;
load('ANO_roi_edge');
load('Step_4_Angle_Search_Result');
STEP_0_Parameters;
img_name=Img_filename_list;
mkdir Image_Analysed
mkdir Image_Analysed_ROI_absent
mkdir Image_Analysed_ROI_absent_before_warping

%% Prepartion : indices for both the anchor and non-anchor imgs
img_idx=anc_img_IDs;
Expand All @@ -18,7 +17,8 @@
img_AP = ap_found;
else
for img_ID=1:length(img_idx)-1
img_AP=[img_AP, linspace(ap_found(img_ID),ap_found(img_ID+1),img_idx(img_ID+1)-img_idx(img_ID)+1)];
img_AP=[img_AP, linspace(ap_found(img_ID),...
ap_found(img_ID+1),img_idx(img_ID+1)-img_idx(img_ID)+1)];
end
end

Expand All @@ -28,42 +28,46 @@
else
img_idx=max(img_idx):-1:min(img_idx);
end
xy_pix_resc_factor = 1;

%% MAIN PART
for img_ID=1:length(img_AP)
disp(['Cell Detection: ', num2str(img_ID), '/', num2str(length(img_AP))]);
parfor img_ID=1:length(img_AP)
disp(['Cell Detection: ', num2str(img_ID), '/', ...
num2str(length(img_AP))]);
img_ID
for color_ch_ID=1:length(Color_Channel_Interest)
if ~isempty(img_info(img_idx(img_ID)).slice_window)
cell_detection_rs(img_ID).img_AP_pos= img_AP(img_ID);

img_Color=(imread(img_name{img_idx(img_ID), Color_Channel_Interest(color_ch_ID)}));
img_Color=(imread(img_name{img_idx(img_ID),...
Color_Channel_Interest(color_ch_ID)}));
try
img_Color=rgb2gray(img_Color);
end
img_Color_pad=zeros(size(img_Color));
img_Color=img_Color(img_info(img_idx(img_ID)).slice_window(1):img_info(img_idx(img_ID)).slice_window(2),...
img_info(img_idx(img_ID)).slice_window(3):img_info(img_idx(img_ID)).slice_window(4));

img_Color_pad=img_Color_pad(img_info(img_idx(img_ID)).slice_window(1):img_info(img_idx(img_ID)).slice_window(2),...
img_info(img_idx(img_ID)).slice_window(3):img_info(img_idx(img_ID)).slice_window(4));
img_Color=img_Color(img_info(img_idx(img_ID)).slice_window(1):...
img_info(img_idx(img_ID)).slice_window(2),...
img_info(img_idx(img_ID)).slice_window(3):...
img_info(img_idx(img_ID)).slice_window(4));
img_Color_pad=img_Color_pad(img_info(img_idx(img_ID)).slice_window(1):...
img_info(img_idx(img_ID)).slice_window(2),...
img_info(img_idx(img_ID)).slice_window(3):...
img_info(img_idx(img_ID)).slice_window(4));
img_Color_pad(img_info(img_idx(img_ID)).bnd_pix_ind)=1;
img_Color_pad=(imfill(img_Color_pad));
img_Color_pad=uint8(logical(img_Color_pad));

img_Color=img_Color.*img_Color_pad;
img_Color=padarray(img_Color,round([3000 3000]/(xy_pix)));

atlas_exp_scale_fac=(25/xy_pix)*xy_pix_resc_factor;

img_Color=imresize(img_Color,xy_pix_resc_factor);


%%% detect cells across the whole slice image
cell_detected_all= SomaDetection0827 (img_Color, xy_pix, soma_radius,cell_det_thresh);
cell_detected_all= SomaDetection0827(...
img_Color, xy_pix, soma_radius,cell_det_thresh);

if ~isempty(cell_detected_all)
out_bnd_alpha = ref_boundarypad_0809_step5( img_Color, xy_pix/xy_pix_resc_factor );
out_bnd=inShape(out_bnd_alpha,cell_detected_all(:,2),cell_detected_all(:,1));
out_bnd_alpha = ref_boundarypad_0809_step5(...
img_Color, xy_pix);
out_bnd=inShape(out_bnd_alpha,cell_detected_all(:,2),...
cell_detected_all(:,1));
cell_detected_all=cell_detected_all(~out_bnd,:);
end

Expand All @@ -76,27 +80,30 @@
cell_detected_all_pos_ind=[];
end

cell_detection_rs(img_ID).Color_Cells(color_ch_ID).cell_locations=cell_detected_all;
cell_detection_rs(img_ID).Color_Cells(color_ch_ID).cell_locations=...
cell_detected_all;

figure; imshow(img_Color);
hold on;
plot(cell_detected_all(:,1), cell_detected_all(:,2), 'ro');

image_analyzed=figure;
imshow(img_Color,[]); hold on
title(strcat({'Image Name : '}, img_name{img_idx(img_ID), Color_Channel_Interest(color_ch_ID)},...
{' - Ch No. '},num2str(color_ch_ID)),'Interpreter', 'none');
title(strcat({'Image Name : '}, img_name{img_idx(img_ID),...
Color_Channel_Interest(color_ch_ID)},...
{' - Ch No. '},num2str(color_ch_ID)),...
'Interpreter', 'none');
if ~isempty(cell_detected_all)
scatter(cell_detected_all(:,1),cell_detected_all(:,2),9,'r','filled')
scatter(cell_detected_all(:,1),...
cell_detected_all(:,2),9,'r','filled')
end

save_name=strcat('/Image_Analysed_ROI_absent/',img_name{img_idx(img_ID), Color_Channel_Interest(color_ch_ID)},'.fig');
save_name=strcat('/Image_Analysed_ROI_absent_before_warping/',...
img_name{img_idx(img_ID),...
Color_Channel_Interest(color_ch_ID)},'.fig');
saveas( image_analyzed,[pwd save_name]);
close(image_analyzed)

% % % [B,RB]=imwarp(A,tform);
% % % [xdataT,ydataT]=transformPointsForward(tform,xdata,ydata);
% % % [xdataI,ydataI]=worldToIntrinsic(RB,xdataT,ydataT);
end
end
end
Expand Down
Loading

0 comments on commit 2cca0f7

Please sign in to comment.