Mutlimedia & MATLAB

 MATLAB is a very useful tool, especially for multimedia use (such as image), since every image is actually a 2D pixels matrix, notice MATLAB is very good tool on matrix. For example, some times we want change the size (pixel size) of an image, yet, we can do that by Paint, but then we don't understand how does it actually work, now look at this MATLAB code writen by myself (Kevin),.. it might be good start... Q: You have an 1024 x 1024 (pixels) image, you want reduce it to 1/4 (which is 256 x 256 pixels), this procedure called pixel replication (down-sampling), show step by step and display the image, Also, after you reduce to 256 x 256, up-sampling back to 1024x1024 and compare the two, explain the difference. The following code write by Kevin Tang, you may used them, but don't copy the entire code, try to understand the concepts~ thanks~ function change_pixel ( picture_file ) % by Kevin Tang % (1) Notice: This function shrink the image from 1024 x 1024 % to 256 x 256 then, zoom out again, compare the differnce, % and is done by pixel replication, % e.g. from 4->8, from ABCD --> AABBCCDD %      from 8->4, from ABCDEFGH --> ACEG % (2) WARRNING: The input image MUST be in pixel of 1024 x 1024 %           otherwise, it will NOT WORK     pic = imread(picture_file); %Read the image % Show the orignal image figure(1), imshow(pic); title('Original Picture [1024x1024]');  %Title of image % Down Sampling to 256 x 256. % The key point is to operate in both row/column, % which take 3 pixel out on every 4 pixel, reduce 75% of infromation % from 1024 --> 256 (factor of 1/4) shrink_pic=zeros(256,256); %make empty img, set matrix to zeros for i=1:256 %for loop on both row/column     for j=1:256         c= 4*(i-1)+1; %take every "4"th sample.         d= 4*(j-1)+1;         shrink_pic(i,j)=pic(c,d); %Image reduce to 1/4     end end % Up Sampling back to 1024 x 1024. % The key point is to copy the pixel back, % every one pixel copy three times, and replace nearst one. % result cause from 256 --> 1024 (factor of 4) zoom_pic=zeros(256,256); for i=1:256 % Make the repelica on both row and column from 1 to 4.     for j=1:256         c=4*(i-1)+1;         d=4*(j-1)+1;         zoom_pic(c:c+3,d:d+3)=shrink_pic(i,j); %Copy 1 pix to other 4.     end end     % Display the shrink image figure(2),imshow(shrink_pic,[]); %the open [] ignore zero pix part title('Shrink Image [256x256]'); % Display the zooming image. figure(3), imshow(zoom_pic,[]); title('Zoom Image back [1024x1024]'); end   Copy Code
 Any question, feel free to asked ^^