How to Partition the MaxIndex into 16 sub-images and calculate a 5-element histogram for each sub-image? How to create the 80-element Edge Histogram Descriptor EHD feature vector by concatenating the 16, 5-element histograms into one vector?

1 次查看(过去 30 天)
rgb_im = imread('0002.png');
new_im=rgb2gray(im2double(rgb_im));
%extract only y component
y=double(new_im(:,:,1));
% define the filters for the 5 types of edges
f1 = zeros(3,3,5);
f1(:,:,1) = [1 2 1;0 0 0;-1 -2 -1]; %vertical
f1(:,:,2) = [-1 0 1;-2 0 2;-1 0 1]; %horizontal
f1(:,:,3) = [2 2 -1;2 -1 -1; -1 -1 -1];% 45 diagonal
f1(:,:,4) = [-1 2 2; -1 -1 2; -1 -1 -1];%135 diagonal
f1(:,:,5) = [-1 0 1;0 0 0;1 0 -1]; % non directional
% iterate over the posible directions
for i = 1:5
g_im(:,:,i) = filter2(f1(:,:,i),y); % apply the sobel mask
end
% calculate the max sobel gradient and index of the orientation
[m, p] = max(g_im,[],3);
%detect the edges using canny
edim = edge(y, 'canny');
%multiply edge image with the types of orientations detected by the Sobel masks
im2 =(p.*edim);
%find hisogram
edhist=hist(im2(:),5)';

回答(2 个)

Walter Roberson
Walter Roberson 2017-7-16
You can use mat2cell to divide images into parts, and then you can cellfun() to do work on each part.
Or, for some calculations, you can use blockproc(). You would be more likely to use blockproc when the block size is fixed than when the rule is that the image has to be divided into a certain number of parts.

Image Analyst
Image Analyst 2017-7-16
See attached demos of blockproc().

Community Treasure Hunt

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

Start Hunting!

Translated by