Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. function out = fsd(in, pal)
  2. [h, w, z] = size(in);
  3. p_h = size(pal, 1);
  4.  
  5. out = zeros(h, w, z, "double");
  6. out(1:h-1, 2:w-1, :) = double(in(1:h-1, 2:w-1, :));
  7.  
  8. pal = double(pal);
  9.  
  10. win = [0 0 7; 3 5 1]/16;
  11.  
  12. for j = 1 : h - 1
  13. for i = 2 : w - 1
  14. old = out(j, i, :);
  15.  
  16. col = old(:)';
  17. col = max(col, [0.0 0.0 0.0]);
  18. col = min(col, [255.0 255.0 255.0]);
  19. col = repmat(col, p_h, 1);
  20.  
  21. tmp = pal - col;
  22. tmp = tmp .^ 2;
  23. tmp = sum(tmp, 2);
  24.  
  25. [c, idx] = min(tmp);
  26. new = cat(3, pal(idx, 1), pal(idx, 2), pal(idx, 3));
  27.  
  28. err = old - new;
  29. errwin = cat(3, err(:,:,1) * win, err(:,:,2) * win, err(:,:,3) * win);
  30.  
  31. out(j : j + 1, i - 1 : i + 1, :) = out(j : j + 1, i - 1 : i + 1, :) + errwin;
  32. out(j, i, :) = new;
  33. end
  34. end
  35.  
  36. out = uint8(out);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement