Guest User

Untitled

a guest
Jul 20th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. function grow()
  2. % rr and rc can be any number provided they are greater than one and whole
  3. % integers.
  4. rr = 2; % ratio to multiply the rows by, i.e. rr = 2 doubles the amount of rows the new picture will have
  5. rc = 2; % same as above but for columns
  6.  
  7. if( rr < 1 || rc < 1) % this program cannot yet downsize pictures!
  8. disp(' This program cannot downsize pictures, run function shrink() instead!');
  9. end
  10.  
  11.  
  12. nc = 800; %image dimensions
  13. nr = 600; %image dimensions
  14.  
  15. Y = zeros(2,2,3,'uint8');
  16. Y(1,1,1) = 255;
  17. Y(1,2,3) = 255;
  18. Y(2,1,2) = 255;
  19. Y(2,2,1:3) = 255;
  20.  
  21. F = imread('watarunfull.jpg'); % reads image from the same folder this matlab .M file is located
  22. %H = imread('watarunfull.jpg');
  23. image(F);
  24.  
  25.  
  26.  
  27. X = zeros(rr*nr,rc*nc,3,'uint8'); % creates 3 dimensional array to replace the picture supplied earlier (columns,rows,rgb of type unsigned integer (8 bytes))
  28.  
  29.  
  30.  
  31. for i = 1:1:nr
  32. for j = 1:1:nc
  33.  
  34. X(i*rr - rr + 1 ,j * rc - rc + 1,1:3) = F(i,j,1:3); % Copies color codes
  35.  
  36.  
  37. end
  38. end
  39.  
  40.  
  41.  
  42. image(X);
  43. pause
  44. blir = bilinearInterpolationRows(X,nr,nc,rr,rc,1);
  45. image(blir);
  46. pause
  47.  
  48. blic = bilinearInterpolationColumns(blir,nr,nc,rr,rc,1);
  49. image(blic);
  50. pause
  51.  
  52.  
  53.  
  54.  
  55.  
  56. for i = 2:rc
  57. blic = bilinearInterpolationColumns(blic,nr,nc,rr,rc,i);
  58. pause
  59. end
  60.  
  61. image(blic);
  62. %E = zeros(nr*rr,nc*rc,'uint8');
  63. for i = 1:1:nr*rr
  64. for j = 1:1:nc*rc
  65. for color = 1:3
  66. % E(i,j,color) = abs(H(i,j,color) - blic(i,j,color)); % Copies color codes
  67.  
  68. end
  69. end
  70. end
  71.  
  72. image(blic);
  73. %imwrite(blic,'dogpixel Linear.jpg');
  74. end
  75.  
  76. % rowlength and columnlength are the number of columns and rows of the old
  77. % image, rowmultiple and columnmultiple are just rc and rr respectively.
  78. function blic = bilinearInterpolationColumns(img,columnlength,rowlength,columnmultiple,rowmultiple,start)
  79.  
  80.  
  81. for x = start:rowmultiple:rowlength*rowmultiple
  82. for y = 1:columnmultiple:columnlength*columnmultiple-columnmultiple
  83. for color = 1:3
  84. for increment = 1:columnmultiple-1
  85.  
  86. img(y+increment,x,color) = (((y+columnmultiple - y - increment)*double(img(y,x,color))) + ((y + increment - y) * double(img(y+columnmultiple,x,color))))/(y + columnmultiple - y) ;
  87. end
  88. end
  89. end
  90. end
  91. blic = img;
  92.  
  93.  
  94.  
  95.  
  96. end
  97.  
  98. % rows and columns are the number of rows and columns of the new larger
  99. % image, rowmultiple and columnmultiple are just rr and rc respectively.
  100. function blir = bilinearInterpolationRows(img,columnlength,rowlength,columnmultiple,rowmultiple,start)
  101.  
  102. for y = start:columnmultiple:columnlength*columnmultiple
  103.  
  104. for x = 1:rowmultiple:rowlength*rowmultiple-rowmultiple
  105. for color = 1:3
  106. for increment = 1:rowmultiple - 1
  107.  
  108. img(y,x+increment,color) = ((rowmultiple - increment)*double(img(y,x,color)) + (increment) * double(img(y,x+rowmultiple,color)))/rowmultiple ;
  109. end
  110. end
  111. end
  112. end
  113.  
  114. blir = img;
  115.  
  116.  
  117.  
  118.  
  119. end
Add Comment
Please, Sign In to add comment