Re: zigzag scan: Image processing function
"Fredrik Bülow" <[email protected]> Sat, 7 Oct 2006 14:50:06 +0200
| Newsgroups | gmane.comp.gnu.octave.sources |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_21198_1222623.1160225406791 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi again! I've done the following. 1. Changed the "argument check" to nargin !=3D 1. I was thinking about putting the whole function in the else part of this if clause. I know that the error statements exits the function so I guess one might as well keep it the way it is. I don't know what the standard way of doing these things within the octave community is. 2. It's perfectly fine to implement the new ordering with mtrx=3Dmtrx' but in order to show off I did it by changing odd and even operations around instead. Since both your and my zigzag behave the same way I also renamed the new function to zagzig. 3. Cleaned the square case a bit by replacing n=3Dsize(mtrx) with n=3Dlength(mtrx). One thing I thought of... If you have lots of matrices A1, A2, A3 and they all are of the same dimensions, then zagzig can be used "once and for all" with massive CPU savings. First make a "index mapping vector" like this: n=3Dsize(A1); i=3Dzagzig(reshape(1:prod(n),n(1),n(2))); Thereafter the zagzigs are given by A1(i), A2(i) and A3(i). I suspect that this is about an order of magnitude faster than doing zagzig(A) for each matrix individually. The perfect way of doing zagzig would be finding out a quick way of generating the i vector without for-loops and if-statements all together. I suspect that this can be done easily but I can't figure out how. Code attached. Cheers Fredrik On 10/7/06, Muthiah Annamalai <[email protected]> wrote: > Hello Fredrik, > I think your code does zigzag on a transposed matrix than the one I am > speaking about (I have in my zigzag function). > > Your code does a zigzag of matrix =3D reshape(1:9,3,3) as follows, > ## 1 4- 7 > ## | / / > ## 2 5 8 > ## / /| > ## 3 - 6 9 > but I would expect the output to be as [1 4 2 3 5 7 8 6 9]; instead. > This is the expected behaviour of a DCT frequency coeffients walk-order. > > I have also added some documentation to your code. Please see that, > and also adjust the code. > > One way I did adjust your code was to add one extra line > > mtrx=3Dmtrx' > > before the if statement. Your code however is not modified, as I figured > you may have another way to do the same without a transpose. > > -Muthu > > > On Fri, 2006-10-06 at 16:40 +0200, Fredrik B=FClow wrote: > > Hi Muthiah! > > > > I took the liberty of writing my own quicker version of zigzag. I've > > also added support for mxn matrices (where m!=3Dn). > > > > Code is attached. > > > > Cheers > > Fredrik B=FClow > > > > On 10/5/06, Muthiah Annamalai <[email protected]> wrote: > > > > > > Hello there, > > > I have a function zigzag() which walks-off a (square)matrix and read= s its > > > elements in a zigzag fashion. It is useful for image processing. > > > > > > Example: > > > octave --eval > > > "x=3D[1:4]'*[1:4];eval('x');tic;printf('%d\n',zigzagscan(x));toc()" > > > -q > > > x =3D > > > > > > 1 2 3 4 > > > 2 4 6 8 > > > 3 6 9 12 > > > 4 8 12 16 > > > > > > 1 > > > 2 > > > 2 > > > 3 > > > 4 > > > 3 > > > 4 > > > 6 > > > 6 > > > 4 > > > 8 > > > 9 > > > 8 > > > 12 > > > 12 > > > 16 > > > Elapsed time is 0.177223 seconds. > > > > > > > > > However I dont know where I should commit it to in Octave-forge. > > > Someone please suggest the right place. > > > > > > Code is attached. > > > > > > Cheers > > > Muthu > > > > > > > > > _______________________________________________ > > > Octave-sources mailing list > > > [email protected] > > > https://www.cae.wisc.edu/mailman/listinfo/octave-sources > > > > > > > > > > > > > > > ------=_Part_21198_1222623.1160225406791 Content-Type: text/x-objcsrc; name=zagzig.m; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: base64 X-Attachment-Id: f_et007xs2 Content-Disposition: attachment; filename="zagzig.m" IyMgQ29weXJpZ2h0IChDKSAyMDA2LCBPY3RvYmVyLCBGcmVkcmlrIEJ1bG93LCA8ZnJlZHJpay5i dWxvd0BnbWFpbC5jb20+CiMjCiMjIFRoaXMgcHJvZ3JhbSBpcyBmcmVlIHNvZnR3YXJlOyB5b3Ug Y2FuIHJlZGlzdHJpYnV0ZSBpdCBhbmQvb3IgbW9kaWZ5CiMjIGl0IHVuZGVyIHRoZSB0ZXJtcyBv ZiB0aGUgR05VIEdlbmVyYWwgUHVibGljIExpY2Vuc2UgYXMgcHVibGlzaGVkIGJ5CiMjIHRoZSBG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ICAgIG10cnggPSAobXRyeC4qb2RkKScgKyAobXRyeC4qKDEtb2RkKSk7CgogICAgIyNO b3cgd2UgbWlycm9yIHRoZSBtYXRyaXguIFRoZSBkZXNpcmVkIHZlY3RvciBpcyBub3cgdGhlCiAg ICAjI2NvbmNhdGVuYXRpb24gb2YgdGhlIGRpYWdvbmFscy4KICAgIG10cng9bXRyeCg6LDErc2l6 ZShtdHJ4LDIpLSgxOnNpemUobXRyeCwyKSkpOwoKICAgICMjUGlja2luZyBvdXQgdGhlIGRpYWdv bmFscy4KICAgIHJ2YWwgID0gW107CiAgICBmb3IgaSA9IG4tMTotMToxLW4KICAgICAgcnZhbD1b cnZhbCBkaWFnKG10cngsaSknXTsKICAgIGVuZGZvcgoKICBlbHNlICNOb3Qgc3F1YXJlIChTbG93 IGNhc2VzKQogICAgbj1zaXplKG10cngpOwogICAgbXRyeD1tdHJ4KDosMStzaXplKG10cngsMikt KDE6c2l6ZShtdHJ4LDIpKSk7CgogICAgIyNQaWNraW5nIG91dCB0aGUgZGlhZ29uYWxzIGFuZCBy ZXZlcnNpbmcgb2RkIG9uZXMgbWFudWFsbHkuCiAgICBydmFsICA9IFtdOwogICAgZm9yIGkgPSBu KDIpLTE6LTE6MS1uKDEpCiAgICAgIG5ldyA9IGRpYWcobXRyeCxpKTsKICAgICAgaWYgZmxvb3Io aS8yKT09aS8yICMjRXZlbj8KCXJ2YWw9W3J2YWwgbmV3KCgxK2xlbmd0aChuZXcpKS0oMTpsZW5n dGgobmV3KSkpJ107CiAgICAgIGVsc2UgICAgICAgICAgICAgICAgIyNPZGQhCglydmFsPVtydmFs IG5ldyddOwogICAgICBlbmRpZgogICAgZW5kZm9yCiAgZW5kaWYKZW5kZnVuY3Rpb24KCg== ------=_Part_21198_1222623.1160225406791 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Octave-sources mailing list [email protected] https://www.cae.wisc.edu/mailman/listinfo/octave-sources ------=_Part_21198_1222623.1160225406791--