Subdomain Posts
MatLab | 5 days ago
MatLab | 6 days ago
MatLab | 10 days ago
MatLab | 10 days ago
MatLab | 11 days ago
PHP | 13 days ago
MatLab | 13 days ago
None | 13 days ago
MatLab | 17 days ago
mIRC | 18 days ago
Recent Posts
None | 0 sec ago
ActionScript 3 | 12 sec ago
None | 18 sec ago
JavaScript | 40 sec ago
Ruby | 47 sec ago
Java | 56 sec ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By zara on the 1st of Feb 2010 06:41:18 PM Download | Raw | Embed | Report
  1. function [ output_picture ] = color_inpaint( input_picture )
  2. %UNTITLED Summary of this function goes here
  3. %   Detailed explanation goes here
  4.  
  5. YCrCb = rgb2ycbcr(input_picture);
  6. clear input_picture;
  7.  
  8. Y = double(YCrCb(:,:,1));
  9. Cb = double(YCrCb(:,:,2));
  10. Cr = double(YCrCb(:,:,3));
  11. clear YCrCb;
  12.  
  13. mask = Cr .* Cb;
  14. mask = mask ~= 16384;
  15. mask = double(mask);
  16.  
  17. mask(:,:) = 1; % for testing purpose. to be commented.
  18. mask(100:end-101,100:end-101) = 0; % for testing purpose. to be commented.
  19.  
  20. f = laplacian(Y);
  21.  
  22. newY =  poisson_solver_function(f, Y, mask);
  23. newCr = poisson_solver_function(f, Cr, mask);
  24. newCb = poisson_solver_function(f, Cb, mask);
  25.  
  26. colored(:,:,1) = uint8(Y);
  27. colored(:,:,2) = uint8(abs(newCb));
  28. colored(:,:,3) = uint8(abs(newCr));
  29.  
  30. output_picture = ycbcr2rgb(colored);
  31.  
  32. end
  33.  
  34.  
  35. %----------------------------------
  36.  
  37.  
  38. function [ result ] = laplacian( picture )
  39. %UNTITLED Summary of this function goes here
  40. %   Detailed explanation goes here
  41.  
  42. [height,width,layer_count] = size(picture);
  43.  
  44. clear layer_count;
  45.  
  46. height = uint32(height);
  47. width = uint32(width);
  48.  
  49. j.html">j = 1:height-1;
  50. k = 1:width-1;
  51.  
  52. gx = zeros(height,width);
  53. gy = zeros(height,width);
  54. gxx = zeros(height,width);
  55. gyy = zeros(height,width);
  56.  
  57. clear height width;
  58.  
  59. gx(j.html">j,k) = (picture(j.html">j,k+1) - picture(j.html">j,k));
  60. gy(j.html">j,k) = (picture(j.html">j+1,k) - picture(j.html">j,k));
  61. gyy(j.html">j+1,k) = gy(j.html">j+1,k) - gy(j.html">j,k);
  62. gxx(j.html">j,k+1) = gx(j.html">j,k+1) - gx(j.html">j,k);
  63.  
  64. clear j.html">j k gx gy;
  65.  
  66. result = gxx + gyy;
  67.  
  68. clear gxx gyy;
  69.  
  70. end
  71.  
  72.  
  73. %----------------------------------
  74.  
  75.  
  76. function [img_direct] = poisson_solver_function(laplacian, boundary, mask)
  77. % function [img_direct] = poisson_solver_functionlaplacian, boundary, mask)
  78. % Inputs; Gx and Gy -> Gradients
  79. % Boundary Image -> Boundary image intensities
  80. % Gx Gy and boundary image should be of same size
  81.  
  82. % Is this code a "direct solver" with dirichlet boundaries ?
  83. % bad for non-rectangular boundaries and other constraints ?
  84.  
  85. [H,W] = size(boundary);
  86.  
  87. % boundary image contains image intensities at boundaries
  88. boundary = boundary .* mask;
  89.  
  90. j.html">j = 100:H-101;
  91. k = 100:W-101;
  92. %j = 2:H-1;
  93. %k = 2:W-1;
  94. boundary_laplacian = zeros(H,W);
  95. boundary_laplacian(j.html">j,k) = -4*boundary(j.html">j,k) + boundary(j.html">j,k+1) + boundary(j.html">j,k-1) + boundary(j-1,k) + boundary(j.html">j+1,k);
  96.  
  97. % subtract boundary points contribution
  98. f1 = laplacian - reshape(boundary_laplacian, H, W);
  99. clear laplacian boundary_laplacian
  100.  
  101. % DST Sine Transform algo starts here
  102. f2 = f1(2:end-1,2:end-1);
  103.  
  104. %compute sine transform
  105. tt = dst(f2);
  106. f2sin = dst(tt')';
  107.  
  108. %compute Eigen Values
  109. [x,y] = meshgrid(1:W-2,1:H-2);
  110. denom = (2*cos(pi*x/(W-1))-2) + (2*cos(pi*y/(H-1)) - 2);
  111.  
  112. %divide
  113. f3 = f2sin./denom;
  114. clear f2sin x y
  115.  
  116. %compute Inverse Sine Transform
  117. tt = idst(f3);
  118. clear f3;
  119. img_tt = idst(tt')';
  120.  
  121. % put solution in inner points; outer points obtained from boundary image
  122. vertzero = zeros(1, W-2);
  123. horzzero = zeros(H,1);
  124.  
  125. plop = vertcat(vertzero, img_tt, vertzero);
  126. plop = horzcat(horzzero, plop, horzzero);
  127.  
  128. img_direct = (boundary .* mask) + (plop .* (1 - mask));
  129.  
  130. end
  131.  
  132.  
  133. %----------------------------------
  134.  
  135.  
  136.  
  137. function b=dst(a,n)
  138. %DST Discrete sine transform (Used in Poisson reconstruction)
  139. % Y = DST(X) returns the discrete sine transform of X.
  140. % The vector Y is the same size as X and contains the
  141. % discrete sine transform coefficients.
  142. % Y = DST(X,N) pads or truncates the vector X to length N
  143. % before transforming.
  144. % If X is a matrix, the DST operation is applied to each
  145. % column. This transform can be inverted using IDST.
  146.  
  147.  
  148. if min(size(a))==1
  149.     if size(a,2)>1
  150.         do_trans = 1;
  151.     else
  152.         do_trans = 0;
  153.     end
  154.     a = a(:);
  155. else
  156.     do_trans = 0;
  157. end
  158.  
  159. if nargin==1, n = size(a,1); end
  160.  
  161. m = size(a,2);
  162.  
  163. % Pad or truncate a if necessary
  164. if size(a,1)<n,
  165.     aa = zeros(n,m);
  166.     aa(1:size(a,1),:) = a;
  167. else
  168.     aa = a(1:n,:);
  169. end
  170.  
  171. y=zeros(2*(n+1),m);
  172. y(2:n+1,:)=aa;
  173. y(n+3:2*(n+1),:)=-flipud(aa);
  174. yy=fft(y);
  175. b=yy(2:n+1,:)/(-2*sqrt(-1));
  176.  
  177. if isreal(a), b = real(b); end
  178. if do_trans, b = b.'; end
  179.  
  180.  
  181.  
  182.  
  183. %----------------------------------
  184.  
  185. function b=idst(a,n)
  186. %IDST Inverse discrete sine transform (Used in Poisson reconstruction)
  187. %
  188. % X = IDST(Y) inverts the DST transform, returning the
  189. % original vector if Y was obtained using Y = DST(X).
  190. % X = IDST(Y,N) pads or truncates the vector Y to length N
  191. % before transforming.
  192. % If Y is a matrix, the IDST operation is applied to
  193. % each column.
  194.  
  195. if nargin==1
  196.     if min(size(a))==1
  197.         n=length(a);
  198.     else
  199.         n=size(a,1);
  200.     end
  201. end
  202.  
  203. nn=n+1;
  204. b=2/nn*dst(a,n);
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: