Image.Image->apply_matrix is not always very useful...
I'm a little busy myself, otherwise I would provide a patch, my suggestion is that someone adds a function that does this to Image.Image:
Image.Image convol(Image.Image i, array(array(array(array(float)))) foo) { Image.Image ret;
array(array(array(array(int)))) foo1= ( array(array(array(array(int)))) ) (foo[*][*][*][*]*100000);
for(int x=0;x<3;x++) { array(int) c1=({ 0,0,0 }); c1[x]=255;
array(array(array(int))) foo2=foo1[*][*][x];
for(int y=0;y<3;y++) { array(array(int)) foo3=foo2[*][*][y]; int sum=`+(0, @ foo3*({}));
array(int) c2=({ 0,0,0 }); c2[x]=255;
Image.Image tmp; tmp=i->gray(@c1)->apply_matrix(foo3,0,0,0, sum?100000.0/sum:1.0)*c2;
if(ret) ret+=tmp; else ret=tmp; } } return ret; }
I've need a function like this twice now, so I think it would be useful. Also, the implementation above is grossly inefficient..
If anybody knows a faster way to do the same thing with the currently available Image operations, let me know.
Possible extentions to this function: o Add the results to an image to avoid the clipping that would occur if you did the addition afterwards. o Add x-stride and y-stride to allow it to compute only every x:th and y:th pixel to allow scaling in the same step. (Is it even possible to scale an image without averaging right now?)
Is it even possible to scale an image without averaging right now?
bitscale()
/ Martin Nilsson (DivX Networks)
Previous text:
2004-08-26 05:11: Subject: nice-to-have-function
Image.Image->apply_matrix is not always very useful...
I'm a little busy myself, otherwise I would provide a patch, my suggestion is that someone adds a function that does this to Image.Image:
Image.Image convol(Image.Image i, array(array(array(array(float)))) foo) { Image.Image ret;
array(array(array(array(int)))) foo1= ( array(array(array(array(int)))) ) (foo[*][*][*][*]*100000);
for(int x=0;x<3;x++) { array(int) c1=({ 0,0,0 }); c1[x]=255;
array(array(array(int))) foo2=foo1[*][*][x];
for(int y=0;y<3;y++) { array(array(int)) foo3=foo2[*][*][y]; int sum=`+(0, @ foo3*({}));
array(int) c2=({ 0,0,0 }); c2[x]=255; Image.Image tmp; tmp=i->gray(@c1)->apply_matrix(foo3,0,0,0, sum?100000.0/sum:1.0)*c2; if(ret) ret+=tmp; else ret=tmp;
} } return ret; }
I've need a function like this twice now, so I think it would be useful. Also, the implementation above is grossly inefficient..
If anybody knows a faster way to do the same thing with the currently available Image operations, let me know.
Possible extentions to this function: o Add the results to an image to avoid the clipping that would occur if you did the addition afterwards. o Add x-stride and y-stride to allow it to compute only every x:th and y:th pixel to allow scaling in the same step. (Is it even possible to scale an image without averaging right now?)
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
What is that code supposed to accomplish? (In plain english or swedish..)
/ Marcus Agehall (PacketFront)
Previous text:
2004-08-26 05:11: Subject: nice-to-have-function
Image.Image->apply_matrix is not always very useful...
I'm a little busy myself, otherwise I would provide a patch, my suggestion is that someone adds a function that does this to Image.Image:
Image.Image convol(Image.Image i, array(array(array(array(float)))) foo) { Image.Image ret;
array(array(array(array(int)))) foo1= ( array(array(array(array(int)))) ) (foo[*][*][*][*]*100000);
for(int x=0;x<3;x++) { array(int) c1=({ 0,0,0 }); c1[x]=255;
array(array(array(int))) foo2=foo1[*][*][x];
for(int y=0;y<3;y++) { array(array(int)) foo3=foo2[*][*][y]; int sum=`+(0, @ foo3*({}));
array(int) c2=({ 0,0,0 }); c2[x]=255; Image.Image tmp; tmp=i->gray(@c1)->apply_matrix(foo3,0,0,0, sum?100000.0/sum:1.0)*c2; if(ret) ret+=tmp; else ret=tmp;
} } return ret; }
I've need a function like this twice now, so I think it would be useful. Also, the implementation above is grossly inefficient..
If anybody knows a faster way to do the same thing with the currently available Image operations, let me know.
Possible extentions to this function: o Add the results to an image to avoid the clipping that would occur if you did the addition afterwards. o Add x-stride and y-stride to allow it to compute only every x:th and y:th pixel to allow scaling in the same step. (Is it even possible to scale an image without averaging right now?)
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
it computes
|foo| |foo[0]| result[x][y] = sum sum image[i][j] * foo[i][j] i=0 j=0
For each pixel. Where foo[x][y] is a 3x3 matrix and image[i][j] is a vector with 3 elements (r,g,b).
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
Previous text:
2004-08-26 07:34: Subject: nice-to-have-function
What is that code supposed to accomplish? (In plain english or swedish..)
/ Marcus Agehall (PacketFront)
Is it supposed to be a "normal" convolution? If so, you should be able to transform the image, multiply and invers-transform. That ought to be faster and (probably) more accurate.
/ Marcus Agehall (PacketFront)
Previous text:
2004-08-26 09:28: Subject: nice-to-have-function
it computes
|foo| |foo[0]|
result[x][y] = sum sum image[i][j] * foo[i][j] i=0 j=0
For each pixel. Where foo[x][y] is a 3x3 matrix and image[i][j] is a vector with 3 elements (r,g,b).
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
(I assume that when you say "transform", you mean "fourier-transform") Transforming/multiplying/transforming is only faster for fairly large kernels. Weather it is more accurate or not depends on what you're doing, and on the size of the kernel and transforms.
When it comes right down to it, I don't really care *how* it does it.
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
Previous text:
2004-08-26 09:35: Subject: nice-to-have-function
Is it supposed to be a "normal" convolution? If so, you should be able to transform the image, multiply and invers-transform. That ought to be faster and (probably) more accurate.
/ Marcus Agehall (PacketFront)
You can use FFT or cosine-transform (which is probably easier). But, you might be right about the size of the kernel affecting the usefullness of the transform.
/ Marcus Agehall (PacketFront)
Previous text:
2004-08-26 17:45: Subject: nice-to-have-function
(I assume that when you say "transform", you mean "fourier-transform") Transforming/multiplying/transforming is only faster for fairly large kernels. Weather it is more accurate or not depends on what you're doing, and on the size of the kernel and transforms.
When it comes right down to it, I don't really care *how* it does it.
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
Don't you mean
|foo| |foo[0]| result[x][y] = sum sum image[x+i][y+j] * foo[i][j] i=0 j=0
? Although having the kernel centered around the pixel instead of below/right might be more useful.
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2004-08-26 09:28: Subject: nice-to-have-function
it computes
|foo| |foo[0]|
result[x][y] = sum sum image[i][j] * foo[i][j] i=0 j=0
For each pixel. Where foo[x][y] is a 3x3 matrix and image[i][j] is a vector with 3 elements (r,g,b).
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
Yes, that is what I mean :)
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
Previous text:
2004-08-26 11:06: Subject: nice-to-have-function
Don't you mean
|foo| |foo[0]|
result[x][y] = sum sum image[x+i][y+j] * foo[i][j] i=0 j=0
? Although having the kernel centered around the pixel instead of below/right might be more useful.
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
No, apply_matrix has a few deficiencies:
1) There is no way to make the red channel of the input affect the green channel of the input.
2) There is no way to supply a different divisor for each channel, which makes operations that has a different gamma for each channel impossible.
Because of these two things, the convol() function has to separate the channels and do 9 different calls to apply_matrix to achive the operation I want. One for each combination of {R,G,B} -> {R,G,B}.
Probably the best way to implement the functionality I want is to extend apply_matrix so that it can:
a) Accept floats as well as integers b) Accept a 3x3 matrices as wel as 3x1
Disclaimer: It's possible that some of this already works, but is undocumented... :)
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
Previous text:
2004-08-26 18:05: Subject: nice-to-have-function
I thought that was what apply_matrix did, but with a common factor (or divisor?) for the result.
/ Mirar
Image.Image convol(Image.Image i, array(array(array(array(float)))) foo)
Not convolve? (Just trying to avoid new master()->resolv issues... :-)
/ Johan Sundström (Achtung Liebe!)
Previous text:
2004-08-26 05:11: Subject: nice-to-have-function
Image.Image->apply_matrix is not always very useful...
I'm a little busy myself, otherwise I would provide a patch, my suggestion is that someone adds a function that does this to Image.Image:
Image.Image convol(Image.Image i, array(array(array(array(float)))) foo) { Image.Image ret;
array(array(array(array(int)))) foo1= ( array(array(array(array(int)))) ) (foo[*][*][*][*]*100000);
for(int x=0;x<3;x++) { array(int) c1=({ 0,0,0 }); c1[x]=255;
array(array(array(int))) foo2=foo1[*][*][x];
for(int y=0;y<3;y++) { array(array(int)) foo3=foo2[*][*][y]; int sum=`+(0, @ foo3*({}));
array(int) c2=({ 0,0,0 }); c2[x]=255; Image.Image tmp; tmp=i->gray(@c1)->apply_matrix(foo3,0,0,0, sum?100000.0/sum:1.0)*c2; if(ret) ret+=tmp; else ret=tmp;
} } return ret; }
I've need a function like this twice now, so I think it would be useful. Also, the implementation above is grossly inefficient..
If anybody knows a faster way to do the same thing with the currently available Image operations, let me know.
Possible extentions to this function: o Add the results to an image to avoid the clipping that would occur if you did the addition afterwards. o Add x-stride and y-stride to allow it to compute only every x:th and y:th pixel to allow scaling in the same step. (Is it even possible to scale an image without averaging right now?)
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
I don't care what it's actually called.
/ Fredrik (Naranek) Hubinette (T minus 2 weeks)
Previous text:
2004-08-26 07:40: Subject: nice-to-have-function
Image.Image convol(Image.Image i, array(array(array(array(float)))) foo)
Not convolve? (Just trying to avoid new master()->resolv issues... :-)
/ Johan Sundström (Achtung Liebe!)
pike-devel@lists.lysator.liu.se