Slicing and tiling images
in
Programming Questions
•
7 months ago
I have written/modified some code to serve my purpose, but after a while it becomes terribly inefficient...
What I am currently doing is in one sketch slicing or tiling images down and producing other files of those individual slices that I then in another sketch put back together various ways, but when I start breaking down images into 5px by 5px squares I get 10s of thousands of small(really small) files that are clumsy to manage. Is there a way to do this same thing without writing files out to another sketch and maniuplating them there ie using the pixel array as opposed to get() if so how?
slicing/tiling code----
int tile=50; //tile dimension
void setup(){
//horizonal/vertical slicing
/*
for(int f=0; f<1; f++) {
String imageName = "2.jpg";//original image
PImage img = loadImage(imageName);
for(int p=0; p<img.height; p=p+5){
PImage slice = img.get(0, p, img.width, 5);
String outName = "slice1width"+"-" +p;
slice.save(outName);
}
}
*/
//tile slicing
for(int f=0; f<1; f++) {
String imageName = "0.jpg";//original image
PImage img = loadImage(imageName);
for(int p=0; p<img.height; p=p+tile){
for(int k=0; k<img.width; k=k+tile){
PImage slice = img.get(k, p, tile,tile);
String outName = "slice"+"-"+p+"-"+k;
slice.save(outName);
}
}
print("done");
}
}
assembly code----
int row=34;
int col=26;
int tile=50;//tile dimension
PImage slices[][]= new PImage[row][col];
void setup()
{
size(1300, 1700);
for (int a=0;a<row;a=a+1) {
for (int b=0;b<col;b=b+1) {
{
slices[a][b]=loadImage("slice-"+a*tile+"-"+b*tile+".tif");
println("loaded "+"slice-"+a*tile+"-"+b*tile+".tif");
}
}
}
}
void draw()
{
for (int p=0; p<row; p=p+1) {
for (int k=0; k<col; k=k+1) {
image(slices[int(random(p))][int(random(k))],k*tile,p*tile);
}
}
if(keyPressed){
saveFrame("50x50-0-"+frameCount+".tif");
}
}
1