ALLfiles = dir('*0013.jpg');
Streams=strings(length(ALLfiles),6);
dbstop if error
for i=1:length(ALLfiles)
dbstop if error
thisfile=ALLfiles(i).name;
OrigImage= imread(thisfile);
if size(OrigImage,3)==3
GrayScaleScratchFULL=rgb2gray(OrigImage);
else
GrayScaleScratchFULL=OrigImage;
end
GrayScaleScratch=adapthisteq(GrayScaleScratchFULL);
greenchannel=OrigImage(:,:,2);
greenchannel(greenchannel>140)=255;
binarytwist=imbinarize(greenchannel);
binaryImage = ~bwareaopen(~binarytwist, 4000);
M = bwareaopen(binaryImage,5);
se = strel('disk',5);
N=imclose(M, se);
texture1 = GrayScaleScratch;
texture1(~N) = 0;
texture2 = GrayScaleScratch;
texture2(N) = 0;
boundary = bwperim(N);
boundary = imdilate(boundary, strel('disk',1));
segmentResults = GrayScaleScratch;
segmentResults(boundary) = 255;
fulldestination = fullfile(destdirectory, thisfile + "_Outline.jpg");
imwrite(segmentResults, fulldestination);
imagebar=sum(binaryImage);
crestbar=1024-imagebar;
[peaks,loc]=findpeaks(crestbar, 'MinPeakProminence', 30);
findpeaks(crestbar, 'MinPeakProminence', 30);
hold on
text(loc+.02,peaks,num2str((1:numel(peaks))'));
n=length(peaks);
Streams(i,1)=thisfile;
for nn=1:n
Streams(i,nn+1)=peaks(nn);
end
StreamLengths = array2table(Streams);
end
writetable(StreamLengths,destdirectory+'StreamLengths.xlsx');
0 Comments
Sign in to comment.