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.97 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 x = 1 : w - 1
  13. postep = floor((x)/(w)*100)
  14. for y = 2 : h - 1
  15. old = out(x, y, :);
  16. old(1,1,:) = max(squeeze(old), [0.0 0.0 0.0]');
  17. old(1,1,:) = min(squeeze(old), [255.0 255.0 255.0]');
  18.  
  19. col = old(:)';
  20. col = repmat(col, p_h, 1);
  21.  
  22. tmp = pal - col;
  23. tmp = tmp .^ 2;
  24. tmp = sum(tmp, 2);
  25.  
  26. [c, idx] = min(tmp);
  27. new = cat(3, pal(idx, 1), pal(idx, 2), pal(idx, 3));
  28.  
  29. err = old - new;
  30. errwin = cat(3, err(:,:,1) * win, err(:,:,2) * win, err(:,:,3) * win);
  31.  
  32. out(x:x+1, y-1:y+1, :) = out(x:x+1, y-1:y+1, :) + errwin;
  33. out(x, y, :) = new;
  34. end
  35. end
  36.  
  37. out = uint8(out);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement