Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function grow()
- % rr and rc can be any number provided they are greater than one and whole
- % integers.
- rr = 2; % ratio to multiply the rows by, i.e. rr = 2 doubles the amount of rows the new picture will have
- rc = 2; % same as above but for columns
- if( rr < 1 || rc < 1) % this program cannot yet downsize pictures!
- disp(' This program cannot downsize pictures, run function shrink() instead!');
- end
- nc = 800; %image dimensions
- nr = 600; %image dimensions
- Y = zeros(2,2,3,'uint8');
- Y(1,1,1) = 255;
- Y(1,2,3) = 255;
- Y(2,1,2) = 255;
- Y(2,2,1:3) = 255;
- F = imread('watarunfull.jpg'); % reads image from the same folder this matlab .M file is located
- %H = imread('watarunfull.jpg');
- image(F);
- 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))
- for i = 1:1:nr
- for j = 1:1:nc
- X(i*rr - rr + 1 ,j * rc - rc + 1,1:3) = F(i,j,1:3); % Copies color codes
- end
- end
- image(X);
- pause
- blir = bilinearInterpolationRows(X,nr,nc,rr,rc,1);
- image(blir);
- pause
- blic = bilinearInterpolationColumns(blir,nr,nc,rr,rc,1);
- image(blic);
- pause
- for i = 2:rc
- blic = bilinearInterpolationColumns(blic,nr,nc,rr,rc,i);
- pause
- end
- image(blic);
- %E = zeros(nr*rr,nc*rc,'uint8');
- for i = 1:1:nr*rr
- for j = 1:1:nc*rc
- for color = 1:3
- % E(i,j,color) = abs(H(i,j,color) - blic(i,j,color)); % Copies color codes
- end
- end
- end
- image(blic);
- %imwrite(blic,'dogpixel Linear.jpg');
- end
- % rowlength and columnlength are the number of columns and rows of the old
- % image, rowmultiple and columnmultiple are just rc and rr respectively.
- function blic = bilinearInterpolationColumns(img,columnlength,rowlength,columnmultiple,rowmultiple,start)
- for x = start:rowmultiple:rowlength*rowmultiple
- for y = 1:columnmultiple:columnlength*columnmultiple-columnmultiple
- for color = 1:3
- for increment = 1:columnmultiple-1
- 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) ;
- end
- end
- end
- end
- blic = img;
- end
- % rows and columns are the number of rows and columns of the new larger
- % image, rowmultiple and columnmultiple are just rr and rc respectively.
- function blir = bilinearInterpolationRows(img,columnlength,rowlength,columnmultiple,rowmultiple,start)
- for y = start:columnmultiple:columnlength*columnmultiple
- for x = 1:rowmultiple:rowlength*rowmultiple-rowmultiple
- for color = 1:3
- for increment = 1:rowmultiple - 1
- img(y,x+increment,color) = ((rowmultiple - increment)*double(img(y,x,color)) + (increment) * double(img(y,x+rowmultiple,color)))/rowmultiple ;
- end
- end
- end
- end
- blir = img;
- end
Add Comment
Please, Sign In to add comment