Advertisement
Guest User

Edge Orientation Histogram

a guest
Sep 14th, 2013
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.35 KB | None | 0 0
  1. %
  2. % [eoh] = edgeOrientationHistogram(im)
  3. %
  4. % Extract the MPEG-7 "Edge Orientation Histogram" descriptor
  5. %
  6. % Input image should be a single-band image, but if it's a multiband (e.g. RGB) image
  7. % only the 1st band will be used.
  8. % Compute 4 directional edges and 1 non-directional edge
  9. % The output "eoh" is a 4x4x5 matrix
  10. %
  11. % The image is split into 4x4 non-overlapping rectangular regions
  12. % In each region, a 1x5 edge orientation histogram is computed (horizontal, vertical,
  13. % 2 diagonals and 1 non-directional)
  14. %
  15. function [eoh] = edgeOrientationHistogram(im)
  16.  
  17. % define the filters for the 5 types of edges
  18. f2 = zeros(3,3,5);
  19. f2(:,:,1) = [1 2 1;0 0 0;-1 -2 -1];
  20. f2(:,:,2) = [-1 0 1;-2 0 2;-1 0 1];
  21. f2(:,:,3) = [2 2 -1;2 -1 -1; -1 -1 -1];
  22. f2(:,:,4) = [-1 2 2; -1 -1 2; -1 -1 -1];
  23. f2(:,:,5) = [-1 0 1;0 0 0;1 0 -1];
  24.  
  25. ys = size(im,1);
  26. xs = size(im,2);
  27.  
  28.  
  29. gf = gaussianFilter(11,1.5);
  30. im = filter2(gf, im(:,:,1));
  31. im2 = zeros(ys,xs,5);
  32. for i = 1:5
  33.     im2(:,:,i) = abs(filter2(f2(:,:,i), im));
  34. end
  35.  
  36. [mmax, maxp] = max(im2,[],3);
  37.  
  38. im2 = maxp;
  39.  
  40. ime = edge(im, 'canny', [], 1.5)+0;
  41. im2 = im2.*ime;
  42.  
  43. eoh = zeros(4,4,6);
  44. for j = 1:4
  45.     for i = 1:4
  46.         clip = im2(round((j-1)*ys/4+1):round(j*ys/4),round((i-1)*xs/4+1):round(i*xs/4));
  47.         eoh(j,i,:) = permute(hist(makelinear(clip), 0:5), [1 3 2]);
  48.     end
  49. end
  50.  
  51. eoh = eoh(:,:,2:6);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement