Advertisement
Guest User

Untitled

a guest
Mar 10th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clear all
  2. img = imread('piesek.jpg');
  3. %% zad 1 i 2
  4. % hist(1:256,1) = uint64(0);
  5. % imgv = img(:,:,1);
  6. % imgv = imgv(:);
  7. % for i=1:numel(imgv)
  8. %     hist(imgv(i)+1) = hist(imgv(i)+1)+1;
  9. % end
  10. % cumul = cumsum(double(hist));
  11. % figure(1)
  12. % bar(hist)
  13. % figure(2)
  14. % bar(cumul)
  15.  
  16. %% zad 3
  17. szary = cv.cvtColor(img,'RGB2GRAY');
  18. colormap(gray(256));
  19. szary1 = szary(:);
  20. szary1 = szary1(:);
  21. hist(1:256,1) = 0;
  22. for i = 1:length(szary1)
  23.     hist(szary1(i)+1) = hist(szary1(i)+1)+1;
  24. end
  25. figure(10)
  26. bar(smooth(hist,90))
  27. hh = smooth(hist,90);
  28. for i = 1:126
  29.     if hh(128-i) < hh(127-i) && hh(128-i) < hh(129-i)
  30.         min = 127 - i - 1;
  31.         break;
  32.     end
  33.     if hh(128+i) < hh(127+i) && hh(128+i) < hh(129+i)
  34.         min = 127 + i - 1;
  35.         break;
  36.     end
  37. end
  38. bin = szary>min;
  39. figure(4)
  40. colormap(gray(2));
  41. image(bin)
  42.  
  43. %% zad 4
  44. figure(5)
  45.  
  46.  XX = cv.threshold(szary,'auto','Method', 'Binary');
  47.  colormap(gray(2));
  48.  image(XX)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement