Getting Average HSV Values from a Directory of JPG Images, Exercises of Control Systems

A matlab function named 'gethsvcolorfromdirectory' which reads jpg images from a specified directory and returns an average hsv value for each image. The function is useful for training color detection models.

Typology: Exercises

2011/2012

Uploaded on 07/30/2012

badsha
badsha 🇮🇳

4.3

(28)

213 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
function hsvAll = getHSVColorFromDirectory(dirName)
%
% function hsvAll = getHSVColorFromDirectory(dirName)
%
% This function is used for "training" the color detection model.
%
% ARGUMENTS:
% dirName: the name of the directory in which the images are stored.
%
% RETURN VALUE:
% hsvAll: this Mx3 matrix, in each row contains the average hsv value of
% of the respective image (of dirName dir).
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Theodoros Giannakopoulos - January 2008
% www.di.uoa.gr/~tyiannak
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
D = dir(dirName);
length(D)
hsvAll = [];
for (i=3:length(D)) % for each file in the directory:
if (strcmpi(D(i).name(end-3:end), '.jpg')==1) % if current file IS
JPG:
RGB = imread([dirName '/' D(i).name]);
HSV = selectPixelsAndGetHSV(RGB, 5);
hsvAll = [hsvAll;HSV];
end
end
docsity.com

Partial preview of the text

Download Getting Average HSV Values from a Directory of JPG Images and more Exercises Control Systems in PDF only on Docsity!

function hsvAll = getHSVColorFromDirectory(dirName)

% % function hsvAll = getHSVColorFromDirectory(dirName) % % This function is used for "training" the color detection model. % % ARGUMENTS: % dirName: the name of the directory in which the images are stored. % % RETURN VALUE: % hsvAll: this Mx3 matrix, in each row contains the average hsv value of % of the respective image (of dirName dir). % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Theodoros Giannakopoulos - January 2008 % www.di.uoa.gr/~tyiannak % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

D = dir(dirName); length(D) hsvAll = [];

for (i=3:length(D)) % for each file in the directory: if (strcmpi(D(i).name(end-3:end), '.jpg')==1) % if current file IS JPG: RGB = imread([dirName '/' D(i).name]); HSV = selectPixelsAndGetHSV(RGB, 5); hsvAll = [hsvAll;HSV]; end end

docsity.com