Skip to content

Commit

Permalink
Merge pull request #1 from Wenlab/develop
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
Physics-Lee authored Apr 16, 2024
2 parents 0a813e6 + 9341242 commit 92ed0bf
Show file tree
Hide file tree
Showing 39 changed files with 224 additions and 64 deletions.
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@

# Demo

The following videos are the results from an experiment of 400 seconds (P.S.: `Or_w3_2023-11-27_20-45-30` in our server). Check them on YouTube.
The following videos are the results from a single experiment. (P.S.: `w3_ND16_2024-04-10_23-28-30` in our server).

* Red Channel
![Demo GIF](/README/demo.gif)

* [Soma + Axon + Dendrite](https://www.youtube.com/watch?v=fDxOE4OOPgU)
Check full videos of this experiment on YouTube.

* [Soma](https://www.youtube.com/watch?v=8xflTEeHHjE)

* [Axon + Dendrite](https://www.youtube.com/watch?v=REDlb_fn01U)

* Green Channel
* [Soma + Axon + Dendrite](https://www.youtube.com/watch?v=4X_8FBpwh8g)

* [Soma](https://www.youtube.com/watch?v=XjRCw8ASres)

* [Axon + Dendrite](https://www.youtube.com/watch?v=386Eiqav1gU)
* [Original](https://www.youtube.com/watch?v=Mb1SpIGwP5I)
* [Soma + Axon + Dendrite](https://www.youtube.com/watch?v=3BWrGnO12g4)
* [Soma](https://www.youtube.com/watch?v=-1cdvQVFOaY)
* [Axon + Dendrite](https://www.youtube.com/watch?v=V4snguF-bec)



Expand Down
Binary file added README/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions code/depracated/fake_color/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
full_path_red = "F:\1_learning\research\taxis of C.elegans\Calcium Imaging\data\WEN0234_check\w1_ND16_2024-04-10_22-57-56\0_Camera-Red_VSC-10629\00006265.tif";
full_path_green = "F:\1_learning\research\taxis of C.elegans\Calcium Imaging\data\WEN0234_check\w1_ND16_2024-04-10_22-57-56\1_Camera-Green_VSC-09321\00006264.tif";

% Step 1: Read the image files
red = imread(full_path_red); % Read the red channel image
green = imread(full_path_green); % Read the green channel image

% Step 2: Horizontally flip the green channel image
green_flipped = fliplr(green); % Flip the green image horizontally

% Step 3: Combine the red and flipped green images into a single image
% Create an empty 3-channel image of the same size
% Note: The blue channel remains zero, so where red and green overlap, the color will be yellow
combined = zeros(size(red, 1), size(red, 2), 3, 'uint8');

% Assign the red channel to the first channel of the RGB image
combined(:, :, 1) = red;

% Assign the flipped green channel to the second channel
combined(:, :, 2) = green_flipped;

imshow(combined);

% Step 4: Save the resultant image
imwrite(combined, 'combined_yellow.tif');
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 20 additions & 13 deletions code/downstream.m → code/main_workflow/downstream.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
% down-stream: `is_outlier.mat`, `.mp4`, `intensity.mat` -> figures of red
% and green channel
%
% analyze_area: "all", "soma", "axon_dendrite".
%
% pooling-method: "max", "median", "mean".
% "max" is more reliable for scanning in z-axis, because
% in a volume max-pooling will direct to the brightest frame.
%
% analyze_worm: "0", "1", "2", "3",...
% 0 for skipping
%
% 2023-12-04, Yixuan Li
%

Expand All @@ -14,21 +23,26 @@
root_folder_path = uigetdir;

%% choose the area that you want to analyze
analyze_area = "all";
analyze_area = "axon_dendrite";

%% change this parameter to the frame per volume of your experiment
frame_per_volume = 5;
volume_per_second = 5;
%% choose the pooling method
pooling_method = "max";

%% choose the worm to be analyzed
analyze_worm = 0;

%% analyze which worm?
analyze_worm = 0; % 0 for skipping
%% change this parameter to the frame per volume of your experiment
frame_per_volume = 25;
volume_per_second = 1;

%% main
if root_folder_path ~= 0
root_list = get_all_folders_of_a_certain_name_pattern_in_a_rootpath(root_folder_path,'w');
[indx,tf] = listdlg('ListString',root_list,'ListSize',[800,600],'Name','Choose files');
if tf==1
for i = indx

%% get folder path
folder_path = root_list{i};

%% is_outlier to is_outlier_union
Expand All @@ -44,13 +58,6 @@
intensity_and_mask_to_intensity(folder_path_Green,analyze_area,frame_per_volume,analyze_worm);

%% I_volume to figures
pooling_method = "mean";
draw_red_green_together(folder_path,pooling_method,analyze_area,analyze_worm,volume_per_second);

pooling_method = "max";
draw_red_green_together(folder_path,pooling_method,analyze_area,analyze_worm,volume_per_second);

pooling_method = "median";
draw_red_green_together(folder_path,pooling_method,analyze_area,analyze_worm,volume_per_second);
end
end
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
%% test
% intensity of frames and mask to intensity of volumes, using
% mean, max or median pooling
%
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ function tif_to_mask_and_mp4(folder_path_red,folder_path_green, ...
video_format = 'MPEG-4';

output_video_red = open_a_video(folder_path_red,video_name_str_red,video_format,frame_per_second);
output_video_red_new = open_a_video(folder_path_red,strrep(video_name_str_red,'_red.mp4','_red_new.mp4'),video_format,frame_per_second);
output_video_red_after_applying_all_template = open_a_video(folder_path_red,strrep(video_name_str_red,'_red.mp4','_red_after_applying_all_template.mp4'),video_format,frame_per_second);
output_video_soma_red = open_a_video(folder_path_red,strrep(video_name_str_red,'_red.mp4','_red_soma.mp4'),video_format,frame_per_second);
output_video_neurite_red = open_a_video(folder_path_red,strrep(video_name_str_red,'_red.mp4','_red_neurite.mp4'),video_format,frame_per_second);

output_video_green = open_a_video(folder_path_green,video_name_str_green,video_format,frame_per_second);
output_video_green_new = open_a_video(folder_path_green,strrep(video_name_str_green,'_green.mp4','_green_new.mp4'),video_format,frame_per_second);
output_video_green_after_applying_all_template = open_a_video(folder_path_green,strrep(video_name_str_green,'_green.mp4','_green_after_applying_all_template.mp4'),video_format,frame_per_second);
output_video_soma_green = open_a_video(folder_path_green,strrep(video_name_str_green,'_green.mp4','_green_soma.mp4'),video_format,frame_per_second);
output_video_neurite_green = open_a_video(folder_path_green,strrep(video_name_str_green,'_green.mp4','_green_neurite.mp4'),video_format,frame_per_second);

Expand Down Expand Up @@ -162,8 +162,8 @@ function tif_to_mask_and_mp4(folder_path_red,folder_path_green, ...
end

%% write to the video after applying all_template
write_to_a_video(output_video_red_new,binary_frame_red);
write_to_a_video(output_video_green_new,binary_frame_green);
write_to_a_video(output_video_red_after_applying_all_template,binary_frame_red);
write_to_a_video(output_video_green_after_applying_all_template,binary_frame_green);

%% save to numerical arrays

Expand Down Expand Up @@ -219,12 +219,12 @@ function tif_to_mask_and_mp4(folder_path_red,folder_path_green, ...

%% Close
close(output_video_red);
close(output_video_red_new);
close(output_video_red_after_applying_all_template);
close(output_video_soma_red);
close(output_video_neurite_red);

close(output_video_green);
close(output_video_green_new);
close(output_video_green_after_applying_all_template);
close(output_video_soma_green);
close(output_video_neurite_green);

Expand Down
File renamed without changes.
64 changes: 39 additions & 25 deletions code/upstream.m → code/main_workflow/upstream.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,31 @@
%
% For opening:
% template: use which channel's binarization result as the template.
% disk_size: larger, open more heavily.
% all_template: "red", "green", "nan".
% soma_template: "red", "green".
% neurite_template: "same", "opposite".
%
% For test:
% is_test: "true", "false".
% You can set it as "true" with setting the start frame and the end frame
% to test the super-parameter.
% disk_size: larger, open more severely.
%
% Open for all:
% You can increase sensation threshold and then use opening for all.
%
% For multi worms:
% If your .tif files contain more than 1 worm (which is often the case when
% we test immobile animals), you can simply write the rectangle containg
% the worm in region_prop.
% Set region_prop_red = [] if only 1 worm.
% the worm in region_prop. eg: region_prop_red =
% [600,800,100,300;480,600,540,680]. And set region_prop_red = [] if only 1 worm.
% For all_template: "nan" is recommended for multi-worm, because different
% worms will have different brighter channel.
%
% Frame per second:
% The fps of you data.
%
% For test:
% is_test: "true", "false".
% You can set it as "true" with setting the start frame and the end frame
% to test the super-parameter.
%
% 2023-12-19, Yixuan Li
%

Expand All @@ -41,34 +47,42 @@
list_green = get_all_folders_of_a_certain_name_pattern_in_a_rootpath(folder_path, 'Green');
folder_path_green = list_green{1};

%% set parameters

% For binarization
%% For binarization
binarization_method = "Gauss_Adapt"; % "Gauss_Adapt" is recommended
sense_red = 0.2; % super-parameter
sense_green = 0.2; % super-parameter

% For opening
all_template = "green"; % "nan" is recommended for multi-worm
soma_template = "red"; % In most cases, red is more dimmer, so is easier to be splitted than green
neurite_template = "opposite"; % "opposite" is recommended
disk_size = 3; % super-parameter
%% For opening which splits the soma and the neurite

% For test
is_test = false;
start_frame = 1;
end_frame = 300;
% "green" is recommended: In most cases, green channel is brighter, so it is more
% suitable to be a template.
all_template = "green";

% "green" is recommended: In most cases, red channel is dimmer, so it is
% easier to be splitted into the soma and the neurite than green channel.
soma_template = "red";

% Open for the whole neuron
% "opposite" is recommended: Given that it is recommended to use dimmer channel as
% soma_template, "opposite" will retain more neurite than "same".
neurite_template = "opposite";

% disk size, super-parameter
disk_size = 3;

%% Opening for the whole neuron
use_open_for_all = true; % true is recommended
disk_size_for_all = 2;
disk_size_for_all = 2; % super-parameter

% For multi worms
% region_prop_red = [600,800,100,300;480,600,540,680;330,500,680,820]; % You can get these by Image-J
%% fps
frame_per_second = 25; % Hz

%% For multi worms
region_prop_red = [];

% fps
frame_per_second = 25; % Hz
%% For test
is_test = false;
start_frame = 1;
end_frame = 300;

%% main
tif_to_mask_and_mp4(folder_path_red,folder_path_green, ...
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions code/main_workflow/write_to_a_video.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function write_to_a_video(output_video,binary_frame)

% Write a binary frame to a video, making 1 becomes 255 and 0 remains 0.
%
% Yixuan Li, 2024-04-15.
%

binary_frame_uint8 = uint8(binary_frame) * 255;
writeVideo(output_video, binary_frame_uint8);

end
26 changes: 26 additions & 0 deletions code/mp4_to_other_files/mp4_to_gif.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
% Define the video file
videoFile = '';

% Create a VideoReader object to read video data
vidObj = VideoReader(videoFile);

% Prepare to write GIF
outputGif = 'output.gif';
delayTime = 1 / vidObj.FrameRate; % Delay time between frames in seconds

% Initialize a variable to control GIF initialization
firstFrame = true;

% Read and write each frame
while hasFrame(vidObj)
frame = readFrame(vidObj); % Read a frame
[imind, cm] = rgb2ind(frame, 256); % Convert frame to indexed image

% Write frame to GIF
if firstFrame
imwrite(imind, cm, outputGif, 'gif', 'Loopcount', inf, 'DelayTime', delayTime);
firstFrame = false; % Update flag after first frame is written
else
imwrite(imind, cm, outputGif, 'gif', 'WriteMode', 'append', 'DelayTime', delayTime);
end
end
27 changes: 27 additions & 0 deletions code/mp4_to_other_files/mp4_to_png.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
% Specify the video file
folderPath = 'F:\1_learning\research\taxis of C.elegans\Calcium Imaging\data\WEN0234_check\w3_ND16_2024-04-10_23-28-30\1_Camera-Green_VSC-09321';
fileName = "Gauss_Adapt_size_3_std_3_sense_0.2000___disk_3___green_after_applying_all_template.mp4";
videoFile = fullfile(folderPath,fileName);

% Create a video reader object
vidObj = VideoReader(videoFile);

% Define the output folder for PNG files
outputFolder = 'F:\1_learning\research\taxis of C.elegans\Calcium Imaging\data\temp';
if ~exist(outputFolder, 'dir')
mkdir(outputFolder); % Create the folder if it doesn't exist
end

% Initialize a frame counter
frameCounter = 0;

% Read and write each frame
while hasFrame(vidObj)
frame = readFrame(vidObj); % Read one frame
frameCounter = frameCounter + 1; % Increment the frame counter
% Create a filename for each output image
filename = fullfile(outputFolder, sprintf('frame_%06d.png', frameCounter));
imwrite(frame, filename); % Write the frame to a PNG file
end

% vidObj closes automatically when the function exits
Loading

0 comments on commit 92ed0bf

Please sign in to comment.