Skip to content

Commit

Permalink
Update to move files to make straighten worms work
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Freitas committed Feb 20, 2023
1 parent 67b3a44 commit 0aed899
Show file tree
Hide file tree
Showing 5 changed files with 941 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
data/*
*.jpg
*.png
scripts/testing/
!data/placeholder.md
.DS_Store
App/
4 changes: 2 additions & 2 deletions scripts/testing/Lightsaver_batch_align_worms.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@

[~,final_save_name,~] = fileparts(img_dir_path);

output_path = fullfile(erase(erase(curr_path,'multiple_samples'),'scripts'),'exported_images');
output_path = fullfile(erase(erase(curr_path,'testing'),'scripts'),'exported_images');
mkdir(output_path);

if isempty(output_name)
output_name = final_save_name;
output_name = [final_save_name ' -- aligned_worms'];
end

[~,message,~] = fileattrib(fullfile(img_dir_path,'*'));
Expand Down
59 changes: 59 additions & 0 deletions scripts/testing/bresenham.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function [x y]=bresenham(x1,y1,x2,y2)

%Matlab optmized version of Bresenham line algorithm. No loops.
%Format:
% [x y]=bham(x1,y1,x2,y2)
%
%Input:
% (x1,y1): Start position
% (x2,y2): End position
%
%Output:
% x y: the line coordinates from (x1,y1) to (x2,y2)
%
%Usage example:
% [x y]=bham(1,1, 10,-5);
% plot(x,y,'or');
x1=round(x1); x2=round(x2);
y1=round(y1); y2=round(y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
steep=abs(dy)>abs(dx);
if steep
t=dx;
dx=dy;
dy=t;
end

%The main algorithm goes here.
if dy==0
q=zeros(dx+1,1);
else
q=[0;diff(mod([floor(dx/2):-dy:-dy*dx+floor(dx/2)]',dx))>=0];
end

%and ends here.

if steep
if y1<=y2
y=[y1:y2]';
else
y=[y1:-1:y2]';
end
if x1<=x2
x=x1+cumsum(q);
else
x=x1-cumsum(q);
end
else
if x1<=x2
x=[x1:x2]';
else
x=[x1:-1:x2]';
end
if y1<=y2
y=y1+cumsum(q);
else
y=y1-cumsum(q);
end
end
22 changes: 22 additions & 0 deletions scripts/testing/find_adjacent_pixel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function [outx,outy] = find_adjacent_pixel(bw,x,y)
try
idy = y-1:y+1;
idx = x-1:x+1;
nhood = bw(idx,idy);

x_hood = [-1,-1,-1;0,0,0;1,1,1];
y_hood = [-1,0,1;-1,0,1;-1,0,1];

[subx,suby] = find(nhood==1);

x_add = x_hood(subx,suby);
y_add = y_hood(subx,suby);

outx = x + x_add;
outy = y + y_add;
catch
outx = [];
outy = [];
end

end
Loading

0 comments on commit 0aed899

Please sign in to comment.