% [threshold,crop] = TestImageRecognition(file,frame,minsize,rotate) % % Function for finding and testing the correct image recognition % parameters. % % Input parameters: % file = Video file % frame = Number of test frame. Choose any frame where you can see the % droplet. % minsize = Minimum area that is recognized as a droplet in pixels (e.g. % 100) % rotate = Video rotation angle (deg). Used to straighten skewed videos. % % Output parameters: % threshold = Threshold for black-and-white conversion (0..1) % crop = Amount video is cropped from bottom. function [threshold,crop]=TestImageRecognition(file,frame,minsize,rotate) % This script is not relevant for writing the report, but it might be % interesting. Probably not. % Open video video=VideoReader(file); org=read(video, frame); %Original image is also needed image=org; % Rotate image if needed if rotate ~= 0 temp=imrotate(image,rotate); % White border instead of black rotationmask = ~imrotate(true(size(image)),rotate); temp(rotationmask&~imclearborder(rotationmask)) = 255; image=temp; end width=size(image,2); height=size(image,1); % Convert to grayscale imgray=rgb2gray(image); % Interactive thresholding by Brandon Kuczenski disp('Adjust the threshold for black-and-white conversion and select "done".'); threshold=thresh_tool(imgray,colormap('gray')); threshold=threshold/255; BW = im2bw(imgray,threshold); disp(['Threshold = ' num2str(threshold)]); % Interactive cropping disp('Crop the image (only lower limit matters) so that substrate is left out. Double click inside cropped area when done.'); h=figure; set(h,'Position',[200 500 width*6 height*3]); axes('position',[0 0 .5 1]) [~,cropcoordinates]=imcrop(BW); crop=height-(cropcoordinates(2)+cropcoordinates(4)); crop=round(crop); disp([num2str(crop) ' pixels cropped.']); % Try to find droplet x-coordinate axes('position',[0.5 crop/height .5 (height-crop)/height]); test=ImageRecognition(org,minsize,threshold,crop,rotate,1); if test > 0 disp('Single object found. Position showed in red.'); elseif test == -1 disp('Droplet not found! Try decreasing "minsize".') else disp('Several "droplets" found! Try increasing "minsize".') end end