It is often needed to display images as a montage side by side in scilab. The following functions will be helpful in doing the same.This program is given under GNU GPL
To create a montage ,just store the urls of the images into an array (say z1). and call the following
[z2,x2]=montage(z1,[500,500],5)
Here 500,500 is the size of the new image formed as a montage,and 5 is the number of images per row.
x2=0 if the process is a success.
Now if you call imshow(z2) you will get the image displayed on the screen.
Now feel free to use the code below under GNUGPL.
Note that SIVP / SIP toolboxes are required for this.
Code Developed by Dr.Kannan Balakrishnan,Department of computer applications,Cochin University of science and technology,cochin-22,India
Also in case of any doubt or clarifications,please feel free to mail me at mullayilkannan (at) gmail.com
function [Frame ,x]=deposit(Frame,Im,x1,y1)
//deposits an image Im in a frame Frame,starting from(x1,y1)
//disp("deposit called/n/n",x1,y1)
t=size(Im)
r=size(t)
if(r(1,2)==2)//greyscale image
I=zeros(t(1),t(2),3)//convert to RGB
I(:,:,1)=Im
I(:,:,2)=Im
I(:,:,3)=Im
else
I=Im
end
//xtemp =size(I);
//print("Size of the image, I");
//disp(xtemp);
[a1,b1,c1]=size(I);
b=size(Frame)
if(a1+x1-1)>b(1)
print "frame size exceeded in function deposit" ;
x=1;
return
end
if(b1+y1-1>b(2))
disp('frame size exceeded in function deposit');
x=1;
return;
end
printf("OKAY");
stacksize(80000000);
//Frame(x1,y1,1)=0.5;
z=zeros(a1+1,b1+1,3);
z(1:a1,1:b1,1:3)=I;//this step is needed to comvert I to a matrix
//of ordinary numbers instead of 0..255
//imshow(z);
m1=max(z);
z=z/m1;
Frame(x1:(x1+a1-1),y1:y1+b1-1,1:3)=z(1:a1,1:b1,1:3);
x=0;
endfunction
function [Frame, x]=resizeAndDeposit(Frame,I,x1,y1,rowsize,columnsize)
//make a copy of the image I resized into rowsize x columnsize and places that in the prescribed position
Z=imresize(I,[rowsize,columnsize],'bicubic')
[Frame,x]=deposit(Frame,Z,x1,y1)
endfunction
function [Frame,x]=montage(Imagearray,Framesize,ImagesInRow)
//here imagearray is an array of imageurls
//framesize is of the form[rows,columns]
//imagesInRow is an integer corresponding to the number of images in a row
//x=0 if the operation is sucessful else 1
var1=size(Imagearray)
nImages=var1(1)//number of images
disp(nImages);
nrows=round(nImages/ImagesInRow+0.49) ;
ncols=ImagesInRow;
disp([nrows,ncols])
Frame=zeros(Framesize(1),Framesize(2));
Imagedim1=round(Framesize(1)/nrows)
Imagedim2=round(Framesize(2)/ncols)
//disp([Imagedim1,Imagedim2]);
count=1;
posx=1;
posy=1;//current x and y positions
for(i=1:nrows)
for(j=1:ncols)
t=imread(Imagearray(count))
//count=count+1;
//disp("**************************************")
//disp("posx:",posx,"posy:",posy,"count:",count);
//disp("**************************************")
;
[Frame,x]=resizeAndDeposit(Frame,t,posx,posy,Imagedim1,Imagedim2)
clear t;
posy=posy+Imagedim2
count=count+1
disp(count);
if(count>nImages)
return;
end
end
posy=1
posx=posx+Imagedim1
end
endfunction
To create a montage ,just store the urls of the images into an array (say z1). and call the following
[z2,x2]=montage(z1,[500,500],5)
Here 500,500 is the size of the new image formed as a montage,and 5 is the number of images per row.
x2=0 if the process is a success.
Now if you call imshow(z2) you will get the image displayed on the screen.
Now feel free to use the code below under GNUGPL.
Note that SIVP / SIP toolboxes are required for this.
Code Developed by Dr.Kannan Balakrishnan,Department of computer applications,Cochin University of science and technology,cochin-22,India
Also in case of any doubt or clarifications,please feel free to mail me at mullayilkannan (at) gmail.com
function [Frame ,x]=deposit(Frame,Im,x1,y1)
//deposits an image Im in a frame Frame,starting from(x1,y1)
//disp("deposit called/n/n",x1,y1)
t=size(Im)
r=size(t)
if(r(1,2)==2)//greyscale image
I=zeros(t(1),t(2),3)//convert to RGB
I(:,:,1)=Im
I(:,:,2)=Im
I(:,:,3)=Im
else
I=Im
end
//xtemp =size(I);
//print("Size of the image, I");
//disp(xtemp);
[a1,b1,c1]=size(I);
b=size(Frame)
if(a1+x1-1)>b(1)
print "frame size exceeded in function deposit" ;
x=1;
return
end
if(b1+y1-1>b(2))
disp('frame size exceeded in function deposit');
x=1;
return;
end
printf("OKAY");
stacksize(80000000);
//Frame(x1,y1,1)=0.5;
z=zeros(a1+1,b1+1,3);
z(1:a1,1:b1,1:3)=I;//this step is needed to comvert I to a matrix
//of ordinary numbers instead of 0..255
//imshow(z);
m1=max(z);
z=z/m1;
Frame(x1:(x1+a1-1),y1:y1+b1-1,1:3)=z(1:a1,1:b1,1:3);
x=0;
endfunction
function [Frame, x]=resizeAndDeposit(Frame,I,x1,y1,rowsize,columnsize)
//make a copy of the image I resized into rowsize x columnsize and places that in the prescribed position
Z=imresize(I,[rowsize,columnsize],'bicubic')
[Frame,x]=deposit(Frame,Z,x1,y1)
endfunction
function [Frame,x]=montage(Imagearray,Framesize,ImagesInRow)
//here imagearray is an array of imageurls
//framesize is of the form[rows,columns]
//imagesInRow is an integer corresponding to the number of images in a row
//x=0 if the operation is sucessful else 1
var1=size(Imagearray)
nImages=var1(1)//number of images
disp(nImages);
nrows=round(nImages/ImagesInRow+0.49) ;
ncols=ImagesInRow;
disp([nrows,ncols])
Frame=zeros(Framesize(1),Framesize(2));
Imagedim1=round(Framesize(1)/nrows)
Imagedim2=round(Framesize(2)/ncols)
//disp([Imagedim1,Imagedim2]);
count=1;
posx=1;
posy=1;//current x and y positions
for(i=1:nrows)
for(j=1:ncols)
t=imread(Imagearray(count))
//count=count+1;
//disp("**************************************")
//disp("posx:",posx,"posy:",posy,"count:",count);
//disp("**************************************")
;
[Frame,x]=resizeAndDeposit(Frame,t,posx,posy,Imagedim1,Imagedim2)
clear t;
posy=posy+Imagedim2
count=count+1
disp(count);
if(count>nImages)
return;
end
end
posy=1
posx=posx+Imagedim1
end
endfunction
jasa website surabaya
ReplyDeletenice share bro, i like your blog.