diff --git a/Test.m b/Test.m index 561f022f35e63a748206ba04040c1b5686c01868..531fef47b228886abfba5747600822e84ad84faf 100644 --- a/Test.m +++ b/Test.m @@ -1,15 +1,33 @@ %% Example Title % Let's use Edvard Munch's - skrik picture -image = imread("colorHistogram/Edvard_Munch_-_Despair_(1894).jpg"); +img = imread("colorHistogram/Edvard_Munch_-_Despair_(1894).jpg"); % Let's also display the picture to see how it originally looks %imshow(image); %% edgeMap - Test of implementation -edgeImage = edgeMap(image); +%edgeImage = edgeMap(img); -imshow(edgeImage); +%imshow(edgeImage); +%% HOG - Test of implementation +% "hog" contains feature vector based on histogram of oriented gradients +% "visual" contains visualization object that can be used in plot method +[hog, visual] = histogramOrientedGradients(img); +figure, +imshow(img), +hold on, +plot(visual), +title("Hog features of image"); + +% Using Cellsize this time +[hog2, visual2] = histogramOrientedGradients(img, 32); + +figure, +imshow(img), +hold on, +plot(visual2), +title("Hog features using Cellsize"); %% Section 2 Title % Description of second code block b = 2; diff --git a/histogramGrayscale.m b/histogramGrayscale.m index 45ec9c9c1cdc229ce5644ed478626ff044d0c30f..0f55deb78e481bd972956d84669a972ba7700929 100644 --- a/histogramGrayscale.m +++ b/histogramGrayscale.m @@ -1,6 +1,7 @@ %Returns histogram in grayscale function [out] = histogramGrayscale(image) - %image ideally is already grayscaled rbg2gray() if needed + %Converts image into grayscale + image = rgb2gray(image); [x,y] = size(image); out = zeros(1,255); diff --git a/histogramOrientedGradients.m b/histogramOrientedGradients.m new file mode 100644 index 0000000000000000000000000000000000000000..fb2b8b2ffa3f2603c8e9ff522764b7cd25d6062e --- /dev/null +++ b/histogramOrientedGradients.m @@ -0,0 +1,18 @@ +% Returns histogram of oriented gradients (HOG) feauture vector of an +% image and visualization object that can be used with plot method. +% Useful for training a classifier. +% +% NB! *Requires Computer Vision Toolbox Add-on* +% +function [featureVector, hogVisualization] = histogramOrientedGradients(varargin) + if nargin==1 + img=varargin{1}; + [featureVector, hogVisualization] = extractHOGFeatures(img); + elseif nargin==2 + img=varargin{1}; + size=varargin{2}; + [featureVector, hogVisualization] = extractHOGFeatures(img, "Cellsize",[size size]); + else + error('histogramOrientedGradients only accepts up to 2 input arguments!') + end +end \ No newline at end of file