How to extract features from a ROI exported table, and use the features in Classification learner APP?

5 次查看(过去 30 天)
I am trying to teach myself some pattern recognition skills from different tutorials. I know we can use ROI for a cascade detector, and prepare data of original images for Classification learner APP. But, can I extract features (HOG or bag of features) from a ROI table, and rebuild a table for the Classification Learner APP to read and build a classifier?
For the ROI table, it is a two-column table. First column is the original images' file name, second column is the location of the ROI.
I am now stuck at the first step, which is exact features from ROI. I can exact HOG features from a single image, but "extractHOGFeatures()" seems does not like an array of ROI. And "bagOfFeature()" seems need an imageset of original images, instead of ROI.
So, is there a way that I can keep use the ROI exports, beside for cascade?

采纳的回答

Prashant Arora
Prashant Arora 2016-10-24
It is my understanding that you are trying to generate HOG features from a list of images, each with a specified ROI location stored in a Table. The function “extractHOGFeatures()” does not take ROI as arguments directly. However, you can try masking the image using the ROI first, before passing into the “extractHOGFeatures()”. In the code below, 'roiTable' refers to the table name in your workspace with two fields, 'maskLocation' and 'imageLocation'. You can then loop through the table to generate the training data from features.
  • If ROIs are stored as black and white image:
for i = 1:numel(roiTable.maskLocation);
roiMask = imread(roiTable.maskLocation(i)); % This should return a 2-D Logical array
% For colored images, convert the mask to a 3-D matrix
roiMask(:,:,2) = roiMask;
roiMask(:,:,3) = roiMask(:,:,1);
% Read the image
img = imread(roiTable.imageLocation(i));
img_new = img;
img_new(roiMask==0) = 0
[featureVector,hogVisualization] = extractHOGFeatures(img_new);
trainingSet(i,:) = featureVector;
  • If ROIs are saved as polygonal data, you can create a mask using the function “roipoly(img,c,r)” to generate a mask, where ‘c’ and ‘r’ contains x,y coordinates of polygon vertices respectively.

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by