-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lts ldy #22
Open
danyang123
wants to merge
13
commits into
master
Choose a base branch
from
LTS-ldy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Lts ldy #22
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4f4c570
Delete code that is not related to this branch
danyang123 502479b
extract the fish and scatter the bary center and tail
danyang123 8d7d9c0
remove 'removeLargeArea' and create a new folder '3rdPartyLibs'
danyang123 0b7dcc5
Modify variables and function naming
danyang123 4852705
add function that get angle between vector "head-centroids" and vecto…
danyang123 1f541b3
add function that get angle between vector "head-centroids" and vecto…
danyang123 ee11613
Basic functions have been implemented.TODO:1.optimization;2.add labels
danyang123 217639e
conflict
danyang123 6de8c0b
Merge branch'LTS-ldy'of https://github.com/Wenlab/ABLITZER into LTS-ldy
danyang123 74ccd89
schematic diagram
danyang123 079ce5d
Add files via upload
danyang123 4d2875b
update
danyang123 03153cf
Merge branch 'LTS-ldy' of https://github.com/Wenlab/ABLITZER into LTS…
danyang123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,95 @@ | ||
function extractFish() | ||
|
||
[f,p] = uigetfile('*.avi'); | ||
fName = [p,f]; | ||
|
||
vobj = VideoReader(fName); | ||
for i = 1:200 % 200 frames | ||
frame = readFrame(vobj); | ||
grayImg = rgb2gray(frame); | ||
BW = imbinarize(grayImg,'adaptive','ForegroundPolarity','dark','Sensitivity',0.6); | ||
BW2=BW*(-1)+1; | ||
bwFish = bwareaopen(BW2,50000); | ||
bwFish = removeLargeArea(bwFish,100000); | ||
bwFish=bwFish*(-1)+1; | ||
bwFish = bwareaopen(bwFish,10000); | ||
bwFish=bwFish*(-1)+1; | ||
s = regionprops( bwFish,'centroid'); | ||
centroids = cat(1, s.Centroid); | ||
figure(1); | ||
imshow(bwFish,[]); | ||
hold on; | ||
scatter(centroids(:,1),centroids(:,2),20,'b','filled'); | ||
pause(0.1); | ||
[f,p] = uigetfile('*.avi'); | ||
fName = [p,f]; | ||
vobj = VideoReader(fName); | ||
for i = 1:200 % 200 frames as a simple | ||
frame = readFrame(vobj); | ||
grayImg = rgb2gray(frame); | ||
BW = imbinarize(grayImg,'adaptive','ForegroundPolarity','dark','Sensitivity',0.6); | ||
BW = bwareaopen(BW,10000); % Remove objects in image containing fewer than 10000 pixels which often appear in the fish brain | ||
BW2 = BW*(-1)+1; | ||
bwFish1 = bwareaopen(BW2,50000); % Remove objects in image containing fewer than 50000 pixels | ||
bwFish2 = bwareaopen(bwFish1,80000); % Remove the fish from image | ||
bwFish = bwFish1 - bwFish2; % get the fish from image | ||
s = regionprops( bwFish,'centroid'); | ||
centroids = cat(1, s.Centroid); | ||
figure(1); | ||
imshow(bwFish,[]); | ||
hold on; | ||
scatter(centroids(:,1),centroids(:,2),20,'b','filled'); | ||
pause(0.1); | ||
|
||
%% scatter the tail of the two fishes | ||
[B,~] = bwboundaries(bwFish,'noholes'); | ||
|
||
L = bwlabel(bwFish); %get the points of two fishes | ||
[fish_x, fish_y] = find(L==1); | ||
fish=[fish_x,fish_y]'; | ||
C=B{1,1}; | ||
tail = find_tail(C,fish); | ||
scatter(tail(2,1),tail(1,1),20,'r','o') | ||
pause(0.1); | ||
disp(i); | ||
end | ||
[B,~] = bwboundaries(bwFish,'noholes'); | ||
L = bwlabel(bwFish); %get the points of two fishes | ||
[fish_x, fish_y] = find(L==1); | ||
fish = [fish_x,fish_y]'; | ||
C = B{1,1}; | ||
tail = find_tail(C,fish); | ||
scatter(tail(2,1),tail(1,1),20,'r','o') | ||
pause(0.1); | ||
disp(i); | ||
end | ||
end | ||
|
||
%% function:get the point of tail | ||
function head = find_tail(B,fish) | ||
c = minBoundingBox(B'); | ||
C = zeros(2,1); | ||
C(1) = norm(c(:,1)-c(:,2)); | ||
C(2) = norm(c(:,1)-c(:,4)); | ||
min_norm_c=min(C); | ||
if min_norm_c==C(1) | ||
f1=c(:,1); f2=c(:,2); f3=c(:,3);f4=c(:,4); | ||
else | ||
f1=c(:,2); f2=c(:,3); f3=c(:,4);f4=c(:,1); | ||
end | ||
f1_m = (f1+f2)./2; f2_m=(f3+f4)./2; | ||
f3_m = (f2+f3)./2; f4_m=(f4+f1)./2; | ||
[f_mid,D]=find_D(fish,f1_m,f2_m,f3_m,f4_m); | ||
D_norm=sqrt(D(1,:).^2+D(2,:).^2); | ||
min_D_norm=min(D_norm); | ||
idx=find(D_norm==min_D_norm); | ||
head=D(:,idx)+f_mid; | ||
c = minBoundingBox(B'); | ||
C = zeros(2,1); | ||
C(1) = norm(c(:,1) - c(:,2)); | ||
C(2) = norm(c(:,1) - c(:,4)); | ||
min_norm_c = min(C); | ||
if min_norm_c == C(1) | ||
f1 = c(:,1); f2 = c(:,2); f3 = c(:,3); f4 = c(:,4); | ||
else | ||
f1 = c(:,2); f2 = c(:,3); f3 = c(:,4); f4 = c(:,1); | ||
end | ||
f1_m = (f1+f2)./2; f2_m = (f3+f4)./2; | ||
f3_m = (f2+f3)./2; f4_m = (f4+f1)./2; | ||
[f_mid,D] = find_D(fish,f1_m,f2_m,f3_m,f4_m); | ||
D_norm = sqrt(D(1,:).^2+D(2,:).^2); | ||
min_D_norm = min(D_norm); | ||
idx = find(D_norm == min_D_norm); | ||
head = D(:,idx) + f_mid; | ||
end | ||
|
||
%% get a matrix of distance and f_mid | ||
function [f_mid,D]=find_D(fish,f1_m,f2_m,f3_m,f4_m) | ||
k=(f3_m(1,1)- f4_m(1,1))./(f3_m(2,1)- f4_m(2,1)); | ||
b=f3_m(1,1)-k.*f3_m(2,1); | ||
if f3_m(2,1)== f4_m(2,1) | ||
num1=length(find(fish(2,:)-f3_m(2,1)<0)); | ||
num2=length(find(fish(2,:)-f3_m(2,1)>0)); | ||
if num1>num2 | ||
if f1_m(2,1)>f2_m(2,1) | ||
f_mid=f1_m; D=fish-f1_m; | ||
else | ||
f_mid=f2_m; D=fish-f2_m; | ||
end | ||
function [f_mid,D] = find_D(fish,f1_m,f2_m,f3_m,f4_m) | ||
k = (f3_m(1,1) - f4_m(1,1))./(f3_m(2,1) - f4_m(2,1)); | ||
b = f3_m(1,1) - k.*f3_m(2,1); | ||
if f3_m(2,1) == f4_m(2,1) | ||
num1 = length(find(fish(2,:) - f3_m(2,1)<0)); | ||
num2 = length(find(fish(2,:) - f3_m(2,1)>0)); | ||
if num1 > num2 | ||
if f1_m(2,1) > f2_m(2,1) | ||
f_mid = f1_m; D = fish - f1_m; | ||
else | ||
if f1_m(2,1)<f2_m(2,1) | ||
f_mid=f1_m; D=fish-f1_m; | ||
else | ||
f_mid=f2_m; D=fish-f2_m; | ||
end | ||
f_mid = f2_m; D = fish - f2_m; | ||
end | ||
|
||
else | ||
num1=length(find(k.*fish(2,:)+b-fish(1,:)<0)); | ||
num2=length(find(k.*fish(2,:)+b-fish(1,:)>0)); | ||
if num1>num2 | ||
else | ||
if f1_m(2,1) < f2_m(2,1) | ||
f_mid = f1_m; D = fish - f1_m; | ||
else | ||
f_mid = f2_m; D = fish - f2_m; | ||
end | ||
end | ||
else | ||
num1 = length(find(k.*fish(2,:)+b-fish(1,:)<0)); | ||
num2 = length(find(k.*fish(2,:)+b-fish(1,:)>0)); | ||
if num1 > num2 | ||
if f1_m(1,1) < f2_m(1,1) | ||
f_mid=f1_m; D=fish-f1_m; | ||
f_mid = f1_m; D = fish - f1_m; | ||
else | ||
f_mid=f2_m; D=fish-f2_m; | ||
f_mid = f2_m; D = fish - f2_m; | ||
end | ||
else | ||
else | ||
if f1_m(1,1) > f2_m(1,1) | ||
f_mid=f1_m; D=fish-f1_m; | ||
f_mid = f1_m; D = fish - f1_m; | ||
else | ||
f_mid=f1_m; D=fish-f2_m; | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find_D seems not meaningful, better to describe the goal of the function a little bit. The same for "f_mid".