Here we are going to learn how to divide an image and save each part into different files. As we have already seen earlier that we can insert a image/profile picture in Facebook chat.
Inserting Profile Picture: http://viblogs.wordpress.com/2012/06/22/inserting-profile-picture-in-facebook-chat/
But the size of those images inserted were too small, now if we want to insert larger images in the Facebook chat then we are simply going to insert multiple images alligned properly so that it appears to be a big image, I call it as the ‘Jumbo Image’.
Now we can divide the image manually in the paint and taking equal part at a time, but this method is too tedious and is neither too accurate. So, the simpler way out is to use MATLAB to do the job for us. So here we will be dividing the image into multiple parts(nXm) and then uploading all the images, so that when we insert them in the chat we get a Jumbo Image in the chat box comprising of various small images that we had uploaded earlier.
Here is the MATLAB code to divide a simgle image into multiple parts and saving each part into a different file:
clear; % removes all variables from the workspace, releasing them from system memory
Image = imread(‘https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-prn1/31744_103452216370510_2308261_n.jpg’);
%Taking the image from the given URL, it could have been the name of the file with extension if the root folder
n =3; %defining the number of rows
m =3; %defining the number of columns
a=’a'; %defining a random file name
NewImage = ‘newimage.gif'; %granting permission to create a file and write in it
Image = imresize(Image, [512 512]); %resizing the image, this is a mandatory step
rf = floor(512/n); %generating the number of row pixels in the new file
cf = floor(512/m); %generating the number of row pixels in the new file
for v = 1:n
for s = 1:m %nXm files need to be made
startr = (v-1)*rf;
startc = (s-1)*cf;
for i = 1 : rf
for j = 1 : cf
for k = 1:3 %loop for RGB values
Img1(i,j,k) = Image(startr+i, startc+j,k);
a = strcat(a,’a’); %generating a new file name
NewImage = strcat(a,’.jpg’);
imwrite( Img1, NewImage);
It is generally adviced to make a seperate folder in your PC for each Jumbo Image, it simple makes the handing of the files simpler.