%matlab code
clc;
clear all;
CAMERA = videoinput('pointgrey', '1');
start(CAMERA);
pause(1);
a = serial('COM3','BaudRate',9600);
fopen(a);
pause(1);
fprintf(a,'%i',index)
fclose(a)
for i = 1:20
filename = sprintf('testtry%02d.jpg',i);
img = im2double(getsnapshot(CAMERA));
img = rgb2gray(img);
stop(CAMERA)
imwrite(img,filename)
end
D = 'C:\Users\PRL\Desktop\just';
S = dir(fullfile(D,'*.jpg')); % pattern to match filenames.
for k = 1:numel(S)
F = fullfile(D,S(k).name);
a(k) = bodekke(F);
end
plot(a);
[m,index] = max(a)
hold on
plot(index,m,'*')
hold off
title("bodekke with spot images")
function[addition] = bodekke(imagename)
im = double(imread(imagename))
bd = [-1 0 1]
cbd = conv2(im,bd)
squaredcbd = cbd.^2
addition = sum(squaredcbd(:))
end