yorick-imutil-0.5.7/0000755000076500001440000000000011504165164013714 5ustar frigautusersyorick-imutil-0.5.7/insort.c0000644000076500001440000000520010730001326015360 0ustar frigautusers/* * A library of sorting functions * * Written by: Ariel Faigon, 1987 * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details (to receive a copy of the GNU * General Public License, write to the Free Software Foundation, Inc., 675 * Mass Ave, Cambridge, MA 02139, USA). * */ #include #include "sort.h" /*------------------------------------------------------------------- * This file shouldn't be touched. * For customizable parameters, see 'sort.h' *-----------------------------------------------------------------*/ /* | void insort (array, len) | KEY_T array[]; | int len; | | Abstract: Sort array[0..len-1] into increasing order. | | Method: Optimized insertion-sort (ala Jon Bentley) */ void insort_long (long *array, int len) { int i, j; long temp; for (i = 1; i < len; i++) { /* invariant: array[0..i-1] is sorted */ j = i; /* customization bug: SWAP is not used here */ temp = array[j]; while (j > 0 && GT(array[j-1], temp)) { array[j] = array[j-1]; j--; } array[j] = temp; } } void insort_float (array, len) register float array[]; register int len; { register int i, j; register float temp; for (i = 1; i < len; i++) { /* invariant: array[0..i-1] is sorted */ j = i; /* customization bug: SWAP is not used here */ temp = array[j]; while (j > 0 && GT(array[j-1], temp)) { array[j] = array[j-1]; j--; } array[j] = temp; } } void insort_double (array, len) register double array[]; register int len; { register int i, j; register double temp; for (i = 1; i < len; i++) { /* invariant: array[0..i-1] is sorted */ j = i; /* customization bug: SWAP is not used here */ temp = array[j]; while (j > 0 && GT(array[j-1], temp)) { array[j] = array[j-1]; j--; } array[j] = temp; } } void insort_short (array, len) register short array[]; register int len; { register int i, j; register short temp; for (i = 1; i < len; i++) { /* invariant: array[0..i-1] is sorted */ j = i; /* customization bug: SWAP is not used here */ temp = array[j]; while (j > 0 && GT(array[j-1], temp)) { array[j] = array[j-1]; j--; } array[j] = temp; } } yorick-imutil-0.5.7/sedgesort.c0000644000076500001440000001350310730001301016037 0ustar frigautusers/* * A library of sorting functions * * Written by: Ariel Faigon, 1987 * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details (to receive a copy of the GNU * General Public License, write to the Free Software Foundation, Inc., 675 * Mass Ave, Cambridge, MA 02139, USA). * */ #include #include "sort.h" /*------------------------------------------------------------------- * This file shouldn't be touched. * For customizable parameters, see 'sort.h' *-----------------------------------------------------------------*/ /* 15 has been found empirically as the optimal cutoff value */ #ifndef CUTOFF # define CUTOFF 15 #endif /* | void partial_quickersort (array, lower, upper) | KEY_T array[]; | int lower, upper; | | Abstract: | Sort array[lower..upper] into a partial order | leaving segments which are CUTOFF elements long | unsorted internally. | | Efficiency: | Could be made faster for _worst_ cases by selecting | a pivot using median-of-3. I don't do it because | in practical cases my pivot selection is arbitrary and | thus pretty random, your mileage may vary. | | Method: | Partial Quicker-sort using a sentinel (ala Robert Sedgewick) | | BIG NOTE: | Precondition: array[upper+1] holds the maximum possible key. | with a cutoff value of CUTOFF. */ void partial_quickersort_long (long *array, int lower, int upper) { int i, j; long temp, pivot; if (upper - lower > CUTOFF) { SWAP(array[lower], array[(upper+lower)/2]); i = lower; j = upper + 1; pivot = array[lower]; while (1) { /* * ------------------------- NOTE -------------------------- * ignoring BIG NOTE above may lead to an infinite loop here * --------------------------------------------------------- */ do i++; while (LT(array[i], pivot)); do j--; while (GT(array[j], pivot)); if (j < i) break; SWAP(array[i], array[j]); } SWAP(array[lower], array[j]); partial_quickersort_long (array, lower, j - 1); partial_quickersort_long (array, i, upper); } } void partial_quickersort_float (array, lower, upper) register float array[]; register int lower, upper; { register int i, j; register float temp, pivot; if (upper - lower > CUTOFF) { SWAP(array[lower], array[(upper+lower)/2]); i = lower; j = upper + 1; pivot = array[lower]; while (1) { do i++; while (LT(array[i], pivot)); do j--; while (GT(array[j], pivot)); if (j < i) break; SWAP(array[i], array[j]); } SWAP(array[lower], array[j]); partial_quickersort_float (array, lower, j - 1); partial_quickersort_float (array, i, upper); } } void partial_quickersort_double (array, lower, upper) register double array[]; register int lower, upper; { register int i, j; register double temp, pivot; if (upper - lower > CUTOFF) { SWAP(array[lower], array[(upper+lower)/2]); i = lower; j = upper + 1; pivot = array[lower]; while (1) { do i++; while (LT(array[i], pivot)); do j--; while (GT(array[j], pivot)); if (j < i) break; SWAP(array[i], array[j]); } SWAP(array[lower], array[j]); partial_quickersort_double (array, lower, j - 1); partial_quickersort_double (array, i, upper); } } void partial_quickersort_short (array, lower, upper) register short array[]; register int lower, upper; { register int i, j; register short temp, pivot; if (upper - lower > CUTOFF) { SWAP(array[lower], array[(upper+lower)/2]); i = lower; j = upper + 1; pivot = array[lower]; while (1) { do i++; while (LT(array[i], pivot)); do j--; while (GT(array[j], pivot)); if (j < i) break; SWAP(array[i], array[j]); } SWAP(array[lower], array[j]); partial_quickersort_short (array, lower, j - 1); partial_quickersort_short (array, i, upper); } } /* | void _sedgesort (array, len) | KEY_T array[]; | int len; | | Abstract: | Sort array[0..len-1] into increasing order. | | Method: | Use partial_quickersort() with a sentinel (ala Sedgewick) | to reach a partial order, leave the unsorted segments of | length == CUTOFF to a simpler low-overhead, insertion sort. | | This method seems to me the ultimative sort method in terms | of average efficiency (Skeptic ? try to beat it). | | BIG NOTE: | precondition: array[len] must hold a sentinel (largest | possible value) in order for this to work correctly. | An easy way to do this is to declare an array that has | len+1 elements [0..len], and assign MAXINT or some such | to the last location before starting the sort (see sorttest.c) */ void _sedgesort_long (long *array, int len) { /* * ------------------------- NOTE -------------------------- * ignoring BIG NOTE above may lead to an infinite loop here * --------------------------------------------------------- */ partial_quickersort_long (array, 0, len - 1); insort_long (array, len); } void _sedgesort_float (array, len) register float array[]; register int len; { partial_quickersort_float (array, 0, len - 1); insort_float (array, len); } void _sedgesort_double (array, len) register double array[]; register int len; { partial_quickersort_double (array, 0, len - 1); insort_double (array, len); } void _sedgesort_short (array, len) register short array[]; register int len; { partial_quickersort_short (array, 0, len - 1); insort_short (array, len); } yorick-imutil-0.5.7/imutil.info0000644000076500001440000000651011504153511016067 0ustar frigautusersPackage: imutil Kind: plugin Version: 0.5.7 Revision: 1 Description: Utilitaries for image manipulation License: BSD Author: Francois Rigaut Maintainer: Francois Rigaut OS: Depends: yorick(>=1.6.02), yutils(>=1.0) Source: http://www.maumae.net/yorick/packages/%o/tarballs/imutil-%v-%o.tgz Source-MD5: Source-Directory: contrib/imutil DocFiles: README TODO VERSION NEWS LEGAL doc/README:README.doc doc/FILE_FORMATS doc/*.doc doc/*.pdf doc/*.ps doc/*.tex Homepage: http://www.maumae.net/yorick/doc/plugins.php DescDetail: << Compiled routines for basic but fast image manipulation. Includes 2d bilinear and spline2 interpolation, clipping, 2d dist generator, binning, image rotation, cartesian to polar coordinate transform, gaussian and poisson random generator, fast sort and fast median. All of these functions, with the exceptions of spline2, exist in yorick or the yutils package, but these versions are 2 to 10x faster, being specialized for 2d arrays (hence the name imutil). This plugin is 64bits safe. 1. Content: This plugin includes the following functions: func bilinear(image,arg1,arg2,grid=,minus_one=,outside=) bilinear interpolation on 2D arrays func spline2(image,arg1,arg2,grid=,minus_one=,outside=,mask=) 2D spline interpolation on 2d arrays func bin2d(in,binfact) resampling by neighbor averaging (binning) func cart2pol(image,&r,&theta,xc=,yc=,ntheta=,nr=,tor=,splin=,outside=) cartesian to polar coordinate mapping func clip(inarray,xmin,xmax) set min and max of array to said values func dist(dim,xc=,yc=) generate euclidian distance map func eclat(image) quadrant swap "a la FFT" func gaussdev(dims) generate random array with Gaussian statistic func poidev(vec) compute poisson statistic of input array func rotate2(image,angle,xc=,yc=,splin=,outside=) rotate 2D array using bilinear() or spline2() func sedgesort(vec) sort input vector func sedgemedian(vec) find median of input vector func cpc(im,fmin,fmax) return image clipped at fmin (fraction) and fmax. << DescUsage: << Installation from source: see installation instructions in Makefile. Basically, you will need a C compiler and make/gnumake. You need yorick in your executable path. yorick -batch make.i make make check make install The install puts imutil.i in Y_SITE/i, the imutil.so library in Y_HOME/lib and the imutil_start.i in Y_SITE/i-start See contrib/imutil/check.i for a test suite. Type "yorick -batch check.i" (in this directory) in a terminal to run it. << DescPort: << This package will compile Yorick only on MacOSX 10.3.4 or later, because of a bug in the system math library libm (part of /usr/lib/LibSystem.dylib) in earlier versions of MacOSX 10.3. History: 2008mar10 v0.5.4: Added support for char, short and int in clip() 2007jun14 v0.5.2: corrected nasty bug in spline2 and bilinear for case 2 function(image,dimx,dimy). 2005dec09 v0.5.1: updated the documents, README and info file. 2005dec01 v0.5 : bumped up to v0.5 2005nov08 v0.2.2: fixed local x in sedgesort 2005aug24 v0.2.1: added mask= keyword in spline2 to enable invalid data point in input array. 2005may18 v0.2 : Worked on compatibility with 64 bits. Check API for int/long mix up. Corrected a few. 21Nov2004 removed a call to img_read to read test image (introduced dependency), replaced by a restore. Nov2004 creation. << yorick-imutil-0.5.7/sort.h0000644000076500001440000000355310346320664015063 0ustar frigautusers/*--------------- sort.h --------------*/ /*--------------- sort library customizable file --------------*/ /* * This is the key TYPE. * Replace this typedef by YOUR key type. * e.g. if you're sorting an array of pointers to strings * You should do: * * typedef char * KEY_T * * The keys are the items in the array that you're moving * around using the SWAP macro. * Note: the comparison function may compare any "function" * of this key, it doesn't necessarily need to compare the * key itself. example: you compare the strings pointed to * by the key itself. */ typedef long KEY_T; /* * These are the COMPARISON macros * Replace these macros by YOUR comparison operations. * e.g. if you are sorting an array of pointers to strings * you should define: * * GT(x, y) as (strcmp((x),(y)) > 0) Greater than * LT(x, y) as (strcmp((x),(y)) < 0) Less than * GE(x, y) as (strcmp((x),(y)) >= 0) Greater or equal * LE(x, y) as (strcmp((x),(y)) <= 0) Less or equal * EQ(x, y) as (strcmp((x),(y)) == 0) Equal * NE(x, y) as (strcmp((x),(y)) != 0) Not Equal */ #define GT(x, y) ((x) > (y)) #define LT(x, y) ((x) < (y)) #define GE(x, y) ((x) >= (y)) #define LE(x, y) ((x) <= (y)) #define EQ(x, y) ((x) == (y)) #define NE(x, y) ((x) != (y)) /* * This is the SWAP macro to swap between two keys. * Replace these macros by YOUR swap macro. * e.g. if you are sorting an array of pointers to strings * You can define it as: * * #define SWAP(x, y) temp = (x); (x) = (y); (y) = temp * * Bug: 'insort()' doesn't use the SWAP macro. */ #define SWAP(x, y) temp = (x); (x) = (y); (y) = temp /*-------------------- End of customizable part -----------------------*/ /*-------------------- DON'T TOUCH BEYOND THIS POINT ------------------*/ extern void insort (); extern void partial_quickersort (); extern void sedgesort (); yorick-imutil-0.5.7/LICENSE0000644000076500001440000004313110727621536014731 0ustar frigautusers GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. yorick-imutil-0.5.7/imutil.i0000644000076500001440000006304011406470461015374 0ustar frigautusers/* imutil Yorick plugin * $Id$ * Francois Rigaut, 2003-2005 * last revision/addition: 2007jun14 * * Copyright (c) 2003, Francois RIGAUT (frigaut@gemini.edu, Gemini * Observatory, 670 N A'Ohoku Place, HILO HI-96720). * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details (to receive a copy of the GNU * General Public License, write to the Free Software Foundation, Inc., 675 * Mass Ave, Cambridge, MA 02139, USA). * * $log$ * */ plug_in, "imutil"; require,"util_fr.i"; //func is_scalar(x) { return (is_array(x) && ! dimsof(x)(1)); } //func is_vector(x) { return (is_array(x) && dimsof(x)(1) == 1); } func cart2pol(image,&r,&theta,xc=,yc=,ntheta=,nr=,tor=,splin=,outside=) /* DOCUMENT cart2pol(image,&r,&theta,xc=,yc=,ntheta=,nr=,tor=, splin=,outside=) Cartesian to Polar coordinate coordinate mapping image : input image, in cartesian coorindate (square grid) optional output: r: 1D vector to hold the r coordinates at which output image is mapped theta: same for theta KEYWORDS: xc, yc: Center for coordinate transform. Note that this is compatible with the center defined by dist(), or rotate2(), but is offset by 0.5 pixels w.r.t what you read on the yorick graphic window. I.e. the center of the bottom- left pixel is (1,1) in this function's conventions, not (0.5,0.5). nr, ntheta: number of points over the output radius and theta range tor: upper output radius value (in pixels) splin: use spline2() instead of bilinear() for the interpolation outside: value for outliers. SEE ALSO: rotate2, spline2, bilinear */ { d = dimsof(image); if (xc==[]) xc=ceil(d(2)/2.+0.5); if (yc==[]) yc=ceil(d(3)/2.+0.5); if (!tor) { tor=max(abs(d(2:3)-_(xc,yc))); } if (!ntheta) ntheta=max(d(2:3)); if (!nr) nr = long(ceil(tor)+1); else nr=long(nr); r = array(1.,ntheta)(-,)*span(0.,tor,nr); theta = span(0.,2*pi,ntheta+1)(1:-1)(-,)*array(1.,nr); x = r*cos(theta)+xc; y = r*sin(theta)+yc; r = r(,1); theta = theta(1,); if (splin) return spline2(image,x,y,outside=outside); return bilinear(image,x,y,outside=outside); } func rotate2(image,angle,xc=,yc=,splin=,outside=) /* DOCUMENT rotate2(image,angle,xc=,yc=,splin=,outside=) Rotate the input image. Angle is in degrees, CCW. KEYWORDS: xc, yc: Center for coordinate transform. Note that this is compatible with the center defined by dist(), or cart2pol(), but is offset by 0.5 pixels w.r.t what you read on the yorick graphic window. I.e. the center of the bottom- left pixel is (1,1) in this function's conventions, not (0.5,0.5). splin: use spline2() instead of bilinear() for the interpolation outside: value for outliers. SEE ALSO: spline2, cart2pol, bilinear */ { angle *= pi/180.; d = dimsof(image); xy = indices(d); if (xc==[]) xc=ceil(d(2)/2.+0.5); if (yc==[]) yc=ceil(d(3)/2.+0.5); xy(,,1)-=xc; xy(,,2)-=yc; x = cos(angle)*xy(,,1) + sin(angle)*xy(,,2); y = -sin(angle)*xy(,,1) + cos(angle)*xy(,,2); x +=xc; y +=yc; if (splin) return spline2(image,x,y,outside=outside); return bilinear(image,x,y,outside=outside); } func bin2d(in,binfact) /* DOCUMENT func bin2d(in,binfact) Returns the input 2D array "in", binned with the binning factor "binfact". The input array X and/or Y dimensions needs not to be a multiple of "binfact"; The final/edge pixels are in effect replicated if needed. This routine prepares the parameters and calls the C routine _bin2d. The input array can be of type long, float or double. Last modified: Dec 15, 2003. Author: F.Rigaut SEE ALSO: _bin2d */ { if ( (binfact-long(binfact)) != 0) write,"*** Warning: binfact has to be an int"; if (binfact<1) error,"binfact has to be >= 1"; binfact = int(binfact); // this *has* to be a int. nx = int(dimsof(in)(2)); ny = int(dimsof(in)(3)); fx = int(ceil(nx/float(binfact))); fy = int(ceil(ny/float(binfact))); // Test type of array and call appropriate routine if (typeof(in) == "int") in=long(in); if (typeof(in) == "long") { // define/allocate output image outData = array(long,[2,fx,fy]); err = _bin2d_long(&in,nx,ny,&outData,fx,fy,binfact); return outData; } else if (typeof(in) == "float") { // define/allocate output image outData = array(float,[2,fx,fy]); err = _bin2d_float(&in,nx,ny,&outData,fx,fy,binfact); return outData; } else if (typeof(in) == "double") { // define/allocate output image outData = array(double,[2,fx,fy]); err = _bin2d_double(&in,nx,ny,&outData,fx,fy,binfact); return outData; } else { error,"Unsupported Data Type"; } } func dist(dim,xc=,yc=) /* DOCUMENT func dist(dim,xc=,yc=) * Return an array which elements are the distance to (xc,yc). xc and * yc can be omitted, in which case they are defaulted to size/2+1. * F.Rigaut, 2003/12/10. * SEE ALSO: */ { dim = long(dim); if (is_scalar(dim)) dim=[2,dim,dim]; if ((is_vector(dim)) && (dim(1)!=2)) error,"Dist only deals with 2D square arrays"; d = array(float,dim); if (xc!=[]) {xc = float(xc-1.);} else {xc = float(dim(2)/2);} if (yc!=[]) {yc = float(yc-1.);} else {yc = float(dim(3)/2);} res = _dist(&d,dim(2),dim(3),xc,yc); return d; } func clip(inarray,xmin,xmax) /* DOCUMENT func clip(inarray, mini, maxi); * Returns the argument, which has been "clipped" to mini * and maxi, i.e. in which all elements lower than "mini" * have been replaced by "mini" and all elements greater * than "maxi" by "maxi". * Either "mini" and "maxi" can be ommited, in which case * the corresponding mini or maxi is not clipped. * Equivalent to the IDL ">" and "<" operators. * * Can clip in place * prompt> clip,a,0.,1. * or out of place * prompt> res = clip(a,0.,1.) * * F.Rigaut, 2001/11/10. * 2003/12/4: Using now a C version which is called from this routine. */ { local x; // Check data type to clip. Only supports long, float and double. if ( (typeof(inarray) != "char") & (typeof(inarray) != "short") & (typeof(inarray) != "int") & (typeof(inarray) != "long") & (typeof(inarray) != "float") & (typeof(inarray) != "double") ) { error,"Unknown Data type in clip"; } sub = am_subroutine(); if (sub) {eq_nocopy,x,inarray;} else {x = inarray;} // Simple check that input limits make sense if ( (xmin != []) && (xmax != []) && (xmin > xmax) ) { error,"xmin > xmax in clip"; } // Have to deal with missing min or max in this lenghthy way: // no min specified: if (xmin == []) { if (typeof(x) == "char") { res = clipmaxchar(&x,char(xmax),numberof(x)); } if (typeof(x) == "short") { res = clipmaxshort(&x,short(xmax),numberof(x)); } if (typeof(x) == "int") { res = clipmaxint(&x,int(xmax),numberof(x)); } if (typeof(x) == "long") { res = clipmaxlong(&x,long(xmax),numberof(x)); } if (typeof(x) == "float") { res = clipmaxfloat(&x,float(xmax),numberof(x)); } if (typeof(x) == "double") { res = clipmaxdouble(&x,double(xmax),numberof(x)); } return x; } // no max specified: if (xmax == []) { if (typeof(x) == "char") { res = clipminchar(&x,char(xmin),numberof(x)); } if (typeof(x) == "short") { res = clipminshort(&x,short(xmin),numberof(x)); } if (typeof(x) == "int") { res = clipminint(&x,int(xmin),numberof(x)); } if (typeof(x) == "long") { res = clipminlong(&x,long(xmin),numberof(x)); } if (typeof(x) == "float") { res = clipminfloat(&x,float(xmin),numberof(x)); } if (typeof(x) == "double") { res = clipmindouble(&x,double(xmin),numberof(x)); } return x; } // min and max specified: if (typeof(x) == "char") { res = clipchar(&x,char(xmin),char(xmax),numberof(x)); } if (typeof(x) == "short") { res = clipshort(&x,short(xmin),short(xmax),numberof(x)); } if (typeof(x) == "int") { res = clipint(&x,int(xmin),int(xmax),numberof(x)); } if (typeof(x) == "long") { res = cliplong(&x,long(xmin),long(xmax),numberof(x)); } if (typeof(x) == "float") { res = clipfloat(&x,float(xmin),float(xmax),numberof(x)); } if (typeof(x) == "double") { res = clipdouble(&x,double(xmin),double(xmax),numberof(x)); } return x; } func eclat(image) /* DOCUMENT func eclat(image) * Equivalent, but significantly faster than roll. Transpose the four main * quadrants of a 2D array. Mostly used for FFT applications. * The C function can be called directly in time critical loops as * _eclat_type,&image,nx,ny * with type = long, float or double (e.g. _eclat_float,...) * * Can invoque in place * prompt> eclat,image * or out of place * prompt> res = eclat(image) * * F.Rigaut, 2001/11/10. * SEE ALSO: roll. */ { local x; nx = int(dimsof(image)(2)); ny = int(dimsof(image)(3)); //fixed 2->3 may18, 2005. sub = am_subroutine(); if (sub) {eq_nocopy,x,image;} else {x = image;} if (typeof(image) == "long") { _eclat_long,&x,nx,ny; } else if (typeof(image) == "float") { _eclat_float,&x,nx,ny; } else if (typeof(image) == "double") { _eclat_double,&x,nx,ny; } else { error,"Unsupported data type";} return x; } func poidev(vec) /* DOCUMENT func poidev(vec) Compute random values following a Poisson Distribution. Input: array containing the desired mean value(s) output: randomized array of same dimension EXAMPLE: p = poidev(array(20.,[2,128,128])); returns a 128x128 array with pixels following a Poisson distrib. of mean=20. SEE ALSO: gaussdev */ { vec = float(vec); _poidev,vec,numberof(vec); return vec; } func gaussdev(dims) /* DOCUMENT func gaussdev(dims) Returns an array (as specified by dims) of random values following a normal distribution of mean=0 and standard deviation = 1. EXAMPLES: gaussdev(100) returns a 100 element vector gaussdev([2,512,512]) returns a 512x512 array print,gaussdev([2,512,512])(rms) 0.991666 SEE ALSO: poidev */ { vec = array(float,dims); _gaussdev,vec,numberof(vec); return vec; } func spline2(image,arg1,arg2,grid=,minus_one=,outside=,mask=) /* DOCUMENT spline2(image,arg1,arg2,grid=,minus_one=,outside=,mask=) Interpolate regularly sampled 2D arrays using 2D spline. spline2(image,nrebin) or spline2(image,dimx,dimy) or spline2(image,x,y,grid=1) or spline2(image,x,y) spline2(image,nrebin) Returns image interpolated by a factor N Output dimension = N * input dimension The whole image is interpolated spline2(image,dimx,dimy) Returns interpolated image Output dimension = dimx * dimy The whole image is interpolated spline2(image,x,y,grix=1) Returns interpolated image on a grid of points specified by the coordinates x & y. The output is a 2D array of dimension numberof(x) * numberof(y). spline2(image,x,y) Returns image interpolated at points of coordinates (x,y). X and Y can be of any dimension, e.g. scalar (but in that case it should be entered as a one element vector to avoid confusion with the second form, e.g. spline2(im,[245.34],[45.3])), vectors (for instance along a line of circle) or can be 2D array to specify an arbitrary transform (e.g. a rotation). This is the general form of spline2. It is significantly slower than the previous forms that take advantage of the cartesian nature of the output coordinates, so don't use it unless it is necessary. NOTE on the input coordinates: In the input image, the lower left pixel has coordinates [xin(1),yin(1)]=[1,1]. Pixels are spaced by one unit, so [xin(2),yin(1)]=[2,1],... KEYWORD minus_one specify that the last column/row should not be extrapolated, i.e. the output image extend from xin(1) to xin(0) inclusive, not beyond (same for y). KEYWORD mask can be used if some of the input image pixels are invalid and not to be used to compute the output image. Bad pixel can be interpolated using mask. Mask is an array of same dimension as image. 0 mark an invalid data point. EXAMPLES: if "image" is a 512x512 image: spline2(image,2) returns image interpolated on a 1024x1024 grid spline2(image,1024,800) returns image interpolated on a 1024x800 grid xreb=100+indgen(400)/2.; yreb=50.4+indgen(200)/2.; spline2(image,xreb,yreb,grid=1) returns image, interpolated in 2D over a XY grid defined by xreb and yreb. spline2(image,[300.3],[200.4]) returns the interpolation of image at point [300.3,200.4] spline2(image,indgen(512),indgen(512)) returns a vector of values interpolated at [x,y] = [[1,1],[2,2],...,[512,512]] x = (indgen(400)/3.+50)*array(1,200)(-,); y = (array(1,400)*(indgen(200)/2.+55)(-,)); spline2(image,x,y) returns a 2D interpolated array at indices defined by x and Y xy = indices(512); alpha = 34*pi/180.; x = cos(alpha)*xy(,,1)+sin(alpha)*xy(,,2); y = -sin(alpha)*xy(,,1)+cos(alpha)*xy(,,2); spline2(image,x,y) returns image rotated by alpha SEE ALSO: bilinear, spline */ { if (structof(image) != float) image=float(image); d = dimsof(image); nx = d(2); ny = d(3); xy = indices([2,nx,ny]); xin = float(xy(,,1)); yin = float(indgen(ny)); xy = []; if (is_void(mask)) mask = short(image*0+1); else mask = short(mask); deriv = image*0.f; if (is_void(arg2)) { //case 1: spline2(image,nrebin) nreb = long(arg1); xreb = float((indgen(nx*nreb)-1.f)/nreb+1.0); yreb = float((indgen(ny*nreb)-1.f)/nreb+1.0); } else if (is_scalar(arg1) && is_scalar(arg2)) { //case 2: spline2(image,dimx,dimy) dimx = long(arg1); dimy = long(arg2); xreb = float((indgen(dimx)-1.f)/dimx*nx+1.0); yreb = float((indgen(dimy)-1.f)/dimy*ny+1.0); } else if (grid == 1) { // case 3: spline2(image,x,y,grid=1) xreb = float(arg1); yreb = float(arg2); } else { // gotta be case 4: spline2(image,x,y) xreb = float(arg1); yreb = float(arg2); if (anyof(dimsof(xreb) != dimsof(yreb))) { error,"X and Y have to have the same dimension"; } npt = numberof(xreb); _s2gen = 1; } if (minus_one) { xreb = xreb(where(xreb <= xin(0))); yreb = yreb(where(yreb <= yin(0))); } nxreb = numberof(xreb); nyreb = numberof(yreb); nvalidx = long(mask(sum,)); wm = where(mask(*)); xin = xin(wm); image = image(wm); wm = []; _splie2,xin,image,nx,ny,deriv,nvalidx; if (_s2gen) { res = array(float,dimsof(xreb)); _spline2,xin,yin,image,deriv,nx,ny,xreb,yreb,npt,nvalidx,res; if (!is_void(outside)) { _mask = where((xreb>xin(0))|(xrebyin(0))|(yrebxin(0))|(xrebyin(0))|(yrebny) } else if (grid == 1) { // case 3 xreb = float(arg1); yreb = float(arg2); } else { // gotta be case 4 xreb = float(arg1); yreb = float(arg2); if (anyof(dimsof(xreb) != dimsof(yreb))) { error,"X and Y have to have the same dimension"; } npt = numberof(xreb); _i2gen = 1; } if (minus_one) { xreb = xreb(where(xreb <= xin(0))); yreb = yreb(where(yreb <= yin(0))); } if (!_i2gen) { nxreb = numberof(xreb); nyreb = numberof(yreb); xreb = xreb*array(1.f,nyreb)(-,); yreb = array(1.f,nxreb)*yreb(-,); } res = array(outside,dimsof(xreb)); _bilinear,image,nx,ny,res,xreb,yreb,numberof(xreb),skipoutside; return res; } func sedgesort(vec) /* DOCUMENT func sedgesort(vec) Fast sort method. Typically 2 to 5 times faster than the yorick stock function. Only valid input is a 1D array. WARNING! Returns the sorted vector. This is different than the stock yorick sort, which returns a vector of indices. SEE ALSO: sort, sedgemedian */ { local x; if (dimsof(vec)(1) != 1) { error,"sedgesort only works on 1d array"; } if (noneof(typeof(vec)==["short","long","float","double"])) { error,swrite(format="sorry, type %s not supported",typeof(x)); } x = _(vec,max(vec)+1); xmin = min(x); x = x - xmin; if (typeof(x)=="short") {_sedgesort_short ,&x,int(numberof(x));} else if (typeof(x)=="long") {_sedgesort_long ,&x,int(numberof(x));} else if (typeof(x)=="float") {_sedgesort_float ,&x,int(numberof(x));} else if (typeof(x)=="double") {_sedgesort_double,&x,int(numberof(x));} return x(1:-1)+xmin; } func sedgemedian(vec) /* DOCUMENT func sedgemedian(vec) Returns the median of the input array (1D). Uses sedgesort fast sort. SEE ALSO: sedgesort, median */ { if (dimsof(vec)(1) != 1) { error,"sedgesort only works on 1d array"; } if (noneof(typeof(vec)==["short","long","float","double"])) { error,swrite(format="sorry, type %s not supported",typeof(x)); } x = _(vec,max(vec)+1); xmin = min(x); x = x - xmin; if (typeof(x)=="short") {_sedgesort_short ,&x,int(numberof(x));} else if (typeof(x)=="long") {_sedgesort_long ,&x,int(numberof(x));} else if (typeof(x)=="float") {_sedgesort_float ,&x,int(numberof(x));} else if (typeof(x)=="double") {_sedgesort_double,&x,int(numberof(x));} x = x(1:-1); len = numberof(x); if (len%2) { //odd# of elements. return x(len/2+1)+xmin; } else { //even# of elements. must return avg value of middle elements return (x(len/2)+x(len/2+1))/2.f+xmin; } } func cpc(im,fmin,fmax) /* DOCUMENT func cpc(im,fmin,fmax) return clipped image at from cmin=fraction fmin of pixel intensity to cmax=fraction fmax of pixel intensity 0 <= fmin < fmax <= 1 example: pli,cpc(im) SEE ALSO: */ { s = sedgesort(im(*)); n = numberof(im); if (fmin==[]) fmin = 0.10; if (fmax==[]) fmax = 0.995; if ((fmin<0)||(fmax<0)) error,"fmin and fmax should be > 0" if ((fmin>1)||(fmax>1)) error,"fmin and fmax should be < 1" if (fmin>fmax) error,"fmin should be < fmax" x1=s(long(round(n*fmin))); x2=s(long(round(n*fmax))); return clip(im,x1,x2); } extern _bin2d_long /* PROTOTYPE int _bin2d_long(pointer in, int nx, int ny, pointer out, int fx, int fy, int binfact) */ extern _bin2d_float /* PROTOTYPE int _bin2d_float(pointer in, int nx, int ny, pointer out, int fx, int fy, int binfact) */ extern _bin2d_double /* PROTOTYPE int _bin2d_double(pointer in, int nx, int ny, pointer out, int fx, int fy, int binfact) */ extern _dist; /* PROTOTYPE void _dist(pointer dptr, long dimx, long dimy, float xc, float yc) */ extern clipchar; /* PROTOTYPE int clipchar(pointer x, char xmin, char xmax, long n) */ extern clipshort; /* PROTOTYPE int clipshort(pointer x, short xmin, short xmax, long n) */ extern clipint; /* PROTOTYPE int clipint(pointer x, int xmin, int xmax, long n) */ extern cliplong; /* PROTOTYPE int cliplong(pointer x, long xmin, long xmax, long n) */ extern clipfloat; /* PROTOTYPE int clipfloat(pointer x, float xmin, float xmax, long n) */ extern clipdouble; /* PROTOTYPE int clipdouble(pointer x, double xmin, double xmax, long n) */ extern clipminchar; /* PROTOTYPE int clipminchar(pointer x, char xmin, long n) */ extern clipminshort; /* PROTOTYPE int clipminshort(pointer x, short xmin, long n) */ extern clipminint; /* PROTOTYPE int clipminint(pointer x, int xmin, long n) */ extern clipminlong; /* PROTOTYPE int clipminlong(pointer x, long xmin, long n) */ extern clipminfloat; /* PROTOTYPE int clipminfloat(pointer x, float xmin, long n) */ extern clipmindouble; /* PROTOTYPE int clipmindouble(pointer x, double xmin, long n) */ extern clipmaxchar; /* PROTOTYPE int clipmaxchar(pointer x, char xmax, long n) */ extern clipmaxshort; /* PROTOTYPE int clipmaxshort(pointer x, short xmax, long n) */ extern clipmaxint; /* PROTOTYPE int clipmaxint(pointer x, int xmax, long n) */ extern clipmaxlong; /* PROTOTYPE int clipmaxlong(pointer x, long xmax, long n) */ extern clipmaxfloat; /* PROTOTYPE int clipmaxfloat(pointer x, float xmax, long n) */ extern clipmaxdouble; /* PROTOTYPE int clipmaxdouble(pointer x, double xmax, long n) */ extern _eclat_long /* PROTOTYPE void _eclat_long(pointer ar, int nx, int ny) */ extern _eclat_float /* PROTOTYPE void _eclat_float(pointer ar, int nx, int ny) */ extern _eclat_double /* PROTOTYPE void _eclat_double(pointer ar, int nx, int ny) */ extern _mynoop1 /* PROTOTYPE int _mynoop1(void) */ extern _gaussdev /* PROTOTYPE void _gaussdev(float array xm, long n) */ extern _poidev /* PROTOTYPE void _poidev(float array xm, long n) */ extern ran1init /* PROTOTYPE void ran1init(void) */ extern _spline2grid /* PROTOTYPE void _spline2grid(float array xin, float array yin, float array image, float array deriv, long nx, long ny, float array xreb, float array yreb, long nxreb, long nyreb, long array nvalidx, float array res) */ extern _spline2 /* PROTOTYPE void _spline2(float array xin, float array yin, float array image, float array deriv, long nx, long ny, float array xout, float array yout, long npt, long array nvalidx, float array res) */ extern _splie2 /* PROTOTYPE void _splie2(float array x, float array image, long nx, long ny, float array deriv, long array nvalidx) */ extern _bilinear /* PROTOTYPE void _bilinear(float array image, long nx, long ny, float array out, float array xout, float array yout, long nout, long skipoutside) */ extern _sedgesort_long /* PROTOTYPE void _sedgesort_long(pointer dataprt, int len) */ extern _sedgesort_float /* PROTOTYPE void _sedgesort_float(pointer dataprt, int len) */ extern _sedgesort_double /* PROTOTYPE void _sedgesort_double(pointer dataptr, int len) */ extern _sedgesort_short /* PROTOTYPE void _sedgesort_short(pointer dataptr, int len) */ // comment following line to have a deterministic random (!) start... ran1init; // init random function for poidev. yorick-imutil-0.5.7/imutil.c0000644000076500001440000002734211406470071015370 0ustar frigautusers/* * Author: Francois Rigaut * * This file contains a number of utility functions, coded in C to gain * execution time. It addresses functionalities that are missing in * yorick, mostly concerning 2D image processing. * * Copyright (c) 2003-2007, Francois Rigaut * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details (to receive a copy of the GNU * General Public License, write to the Free Software Foundation, Inc., 675 * Mass Ave, Cambridge, MA 02139, USA). * */ #include #include /************************************************************************ * noop. For testing and timing. * ************************************************************************/ int _mynoop1() { return (0); } /************************************************************************ * Functions _bin2d * * Returns the input image, rebinned with the specified binning factor * * The input image dimension needs not to be a multiple of the binning * * factor. If it is not the case, the final pixel counts several times * * the edge pixels. * * There are 3 function varieties to deal with longs, float and double. * * Called by function bin2d(in,binfact) in yorickUtils.i * * Last modified: December 15, 2003. * * Author: F.Rigaut * ************************************************************************/ int _bin2d_long(long *in, int nx, int ny, long *out, int fx, int fy, int binfact) { /* Declarations */ int i1,i2,j1,j2,i,j; /* Loop on indices to bin */ for ( i1=0 ; i1=nx ) { i=nx-1;} j = j1*binfact+j2; if ( j>=ny ) { j=ny-1;} out[i1+j1*fx] += in[i+j*nx]; } } } } return (0); } int _bin2d_float(float *in, int nx, int ny, float *out, int fx, int fy, int binfact) { /* Declarations */ int i1,i2,j1,j2,i,j; /* Loop on indices to bin */ for ( i1=0 ; i1=nx ) { i=nx-1;} j = j1*binfact+j2; if ( j>=ny ) { j=ny-1;} out[i1+j1*fx] += in[i+j*nx]; } } } } return (0); } int _bin2d_double(double *in, int nx, int ny, double *out, int fx, int fy, int binfact) { /* Declarations */ int i1,i2,j1,j2,i,j; /* Loop on indices to bin */ for ( i1=0 ; i1=nx ) { i=nx-1;} j = j1*binfact+j2; if ( j>=ny ) { j=ny-1;} out[i1+j1*fx] += in[i+j*nx]; } } } } return (0); } /************************************************************************ * Function _eclat * * Returns results identical to roll(), but faster, as it is dedicated * * to swapping quadrants, for use with FFTs. * * Warning: In-place swapping. * Last modified: December 15, 2003. * * Author: F.Rigaut * ************************************************************************/ void _eclat_long(long *ar, int nx, int ny) { int i,j,k1,k2; long a; for ( i=0 ; i<(nx/2) ; ++i ) { for ( j=0 ; j<(ny/2) ; ++j ) { k1 = i+j*nx; k2 = (i+nx/2)+(j+ny/2)*nx; a = ar[k1]; ar[k1] = ar[k2]; ar[k2] = a; } } for ( i=(nx/2) ; i xmax) x[i]=xmax; } return (0); } int clipshort(short *x, short xmin, short xmax, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } int clipint(int *x, int xmin, int xmax, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } int cliplong(long *x, long xmin, long xmax, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } int clipfloat(float *x, float xmin, float xmax, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } int clipdouble(double *x, double xmin, double xmax, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } /***********************/ int clipminchar(char *x, char xmin, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } int clipmaxshort(short *x, short xmax, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } int clipmaxint(int *x, int xmax, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } int clipmaxlong(long *x, long xmax, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } int clipmaxfloat(float *x, float xmax, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } int clipmaxdouble(double *x, double xmax, long n) { long i = 0; for (i=0;i xmax) x[i]=xmax; } return (0); } void ran1init() { srandom(); /* WARNING! this might be platform specific */ } float ran1() { float norm; norm = 2147483647.f; return random()/norm; } void _poidev(float *xmv, long n) /* all floats -> doubles on June 2010 to avoid SIGFPE for too large input values */ { double gammln(double xx); /* float ran1(long *idum);*/ static double sq,alxm,g,oldm=(-1.0); double xm,em,t,y,y1; long i; for (i=0;i g); } else { /* Use rejection method. */ if (xm != oldm) { oldm=xm; sq=sqrt(2.0*xm); alxm=log(xm); g=xm*alxm-gammln(xm+1.0); } do { do { y=tan(3.1415926535897932384626433832*ran1()); em=sq*y+xm; } while (em < 0.0); em=floor(em); t=0.9*(1.0+y*y)*exp(em*alxm-gammln(em+1.0)-g); } while (ran1() > t); } xmv[i] = (float)em; } } double gammln(double xx) { /* Returns the value ln[?(xx)] for xx>0. */ double x,y,tmp,ser; static double cof[6]={76.18009172947146,-86.50532032941677, 24.01409824083091,-1.231739572450155, 0.1208650973866179e-2,-0.5395239384953e-5}; int j; y=x=xx; tmp=x+5.5; tmp -= (x+0.5)*log(tmp); ser=1.000000000190015; for (j=0;j<=5;j++) ser += cof[j]/++y; return -tmp+log(2.5066282746310005*ser/x); } void _gaussdev(float *xmv, long n) { /* Returns a normally distributed deviate with zero mean and unit variance, using ran1() as the source of uniform deviates. */ /* float ran1(long *idum); */ static int iset=0; static float gset; float fac,rsq,v1,v2; long i; for (i=0;i= 1.0 || rsq == 0.0); fac=sqrt(-2.0*log(rsq)/rsq); gset=v1*fac; iset=1; xmv[i] = v2*fac; } else { iset=0; xmv[i] = gset; } } } yorick-imutil-0.5.7/imutil_start.i0000644000076500001440000000031010346320664016601 0ustar frigautusersautoload, "imutil.i", bin2d, dist, clip, eclat; autoload, "imutil.i", poidev, gaussdev, spline2, bilinear; autoload, "imutil.i", sedgesort, sedgemedian; autoload, "imutil.i", cart2pol, rotate2, cpc; yorick-imutil-0.5.7/Makefile0000644000076500001440000001012011504165164015346 0ustar frigautusersY_MAKEDIR=/usr/lib/yorick/2.2 Y_EXE=/usr/lib/yorick/2.2/bin/yorick Y_EXE_PKGS= Y_EXE_HOME=/usr/lib/yorick/2.2 Y_EXE_SITE=/usr/share/yorick/2.2 # ----------------------------------------------------- optimization flags COPT=$(COPT_DEFAULT) TGT=$(DEFAULT_TGT) # ------------------------------------------------ macros for this package PKG_NAME=imutil PKG_I=imutil.i OBJS=bilinear.o imutil.o insort.o sedgesort.o spline2.o # change to give the executable a name other than yorick PKG_EXENAME=yorick # PKG_DEPLIBS=-Lsomedir -lsomelib for dependencies of this package PKG_DEPLIBS= # set compiler or loader (rare) flags specific to this package PKG_CFLAGS= PKG_LDFLAGS= # list of additional package names you want in PKG_EXENAME # (typically Y_EXE_PKGS should be first here) EXTRA_PKGS=$(Y_EXE_PKGS) # list of additional files for clean PKG_CLEAN= # autoload file for this package, if any PKG_I_START=imutil_start.i # non-pkg.i include files for this package, if any PKG_I_EXTRA= # -------------------------------- standard targets and rules (in Makepkg) # set macros Makepkg uses in target and dependency names # DLL_TARGETS, LIB_TARGETS, EXE_TARGETS # are any additional targets (defined below) prerequisite to # the plugin library, archive library, and executable, respectively PKG_I_DEPS=$(PKG_I) Y_DISTMAKE=distmake include $(Y_MAKEDIR)/Make.cfg include $(Y_MAKEDIR)/Makepkg include $(Y_MAKEDIR)/Make$(TGT) # override macros Makepkg sets for rules and other macros # Y_HOME and Y_SITE in Make.cfg may not be correct (e.g.- relocatable) Y_HOME=$(Y_EXE_HOME) Y_SITE=$(Y_EXE_SITE) # reduce chance of yorick-1.5 corrupting this Makefile MAKE_TEMPLATE = protect-against-1.5 # ------------------------------------- targets and rules for this package # simple example: #myfunc.o: myapi.h # more complex example (also consider using PKG_CFLAGS above): #myfunc.o: myapi.h myfunc.c # $(CC) $(CPPFLAGS) $(CFLAGS) -DMY_SWITCH -o $@ -c myfunc.c insort.o: sort.h sedgesort.o: sort.h # -------------------------------------------------------- end of Makefile osx: all libtool -static -o lib$(PKG_NAME).a $(OBJS) installosx: osx install cp -p lib$(PKG_NAME).a $(Y_HOME)/lib/ # for the binary package production (add full path to lib*.a below): PKG_DEPLIBS_STATIC=-lm PKG_ARCH = $(OSTYPE)-$(MACHTYPE) # or linux or windows PKG_VERSION = $(shell (awk '{if ($$1=="Version:") print $$2}' $(PKG_NAME).info)) # .info might not exist, in which case he line above will exit in error. # packages or devel_pkgs: PKG_DEST_URL = packages package: $(MAKE) $(LD_DLL) -o $(PKG_NAME).so $(OBJS) ywrap.o $(PKG_DEPLIBS_STATIC) $(DLL_DEF) mkdir -p binaries/$(PKG_NAME)/dist/y_home/lib mkdir -p binaries/$(PKG_NAME)/dist/y_home/i-start mkdir -p binaries/$(PKG_NAME)/dist/y_site/i0 cp -p $(PKG_I) binaries/$(PKG_NAME)/dist/y_site/i0/ cp -p $(PKG_NAME).so binaries/$(PKG_NAME)/dist/y_home/lib/ if test -f "check.i"; then cp -p check.i binaries/$(PKG_NAME)/.; fi if test -n "$(PKG_I_START)"; then cp -p $(PKG_I_START) \ binaries/$(PKG_NAME)/dist/y_home/i-start/; fi cat $(PKG_NAME).info | sed -e 's/OS:/OS: $(PKG_ARCH)/' > tmp.info mv tmp.info binaries/$(PKG_NAME)/$(PKG_NAME).info cd binaries; tar zcvf $(PKG_NAME)-$(PKG_VERSION)-$(PKG_ARCH).tgz $(PKG_NAME) distbin: package if test -f "binaries/$(PKG_NAME)-$(PKG_VERSION)-$(PKG_ARCH).tgz" ; then \ ncftpput -f $(HOME)/.ncftp/maumae www/yorick/$(PKG_DEST_URL)/$(PKG_ARCH)/tarballs/ \ binaries/$(PKG_NAME)-$(PKG_VERSION)-$(PKG_ARCH).tgz; fi if test -f "binaries/$(PKG_NAME)/$(PKG_NAME).info" ; then \ ncftpput -f $(HOME)/.ncftp/maumae www/yorick/$(PKG_DEST_URL)/$(PKG_ARCH)/info/ \ binaries/$(PKG_NAME)/$(PKG_NAME).info; fi distsrc: make clean; rm -rf binaries cd ..; tar --exclude binaries --exclude .svn --exclude CVS --exclude *.spec -zcvf \ $(PKG_NAME)-$(PKG_VERSION)-src.tgz yorick-$(PKG_NAME)-$(PKG_VERSION);\ ncftpput -f $(HOME)/.ncftp/maumae www/yorick/$(PKG_DEST_URL)/src/ \ $(PKG_NAME)-$(PKG_VERSION)-src.tgz ncftpput -f $(HOME)/.ncftp/maumae www/yorick/contrib/ \ ../$(PKG_NAME)-$(PKG_VERSION)-src.tgz # -------------------------------------------------------- end of Makefile yorick-imutil-0.5.7/spline2.c0000644000076500001440000000744610730001170015431 0ustar frigautusers/* * Author: Francois Rigaut * * Copyright (c) 2003-2007, Francois Rigaut * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details (to receive a copy of the GNU * General Public License, write to the Free Software Foundation, Inc., 675 * Mass Ave, Cambridge, MA 02139, USA). * * */ #include #include "ydata.h" #include "pstdlib.h" void _splint(float *xa, float *ya, float *y2a, long n, float x, float *y) { long klo,khi,k; float h,b,a; klo=0; khi=n-1; while (khi-klo > 1) { k=(khi+klo) >> 1; if (xa[k] > x) khi=k; else klo=k; } h=xa[khi]-xa[klo]; if (h == 0.0) YError("Bad xa input to routine _splint"); a=(xa[khi]-x)/h; b=(x-xa[klo])/h; *y=a*ya[klo]+b*ya[khi]+((a*a*a-a)*y2a[klo]+(b*b*b-b)*y2a[khi])*(h*h)/6.0; } void _splinf(float *x, float *y, long n, float *y2) { long i,k; float p,qn,sig,un,*u; u = p_malloc(sizeof(float)*(n-1)); y2[0]=u[0]=qn=un=0.0; for (i=1;i<=n-2;i++) { sig=(x[i]-x[i-1])/(x[i+1]-x[i-1]); p=sig*y2[i-1]+2.0; y2[i]=(sig-1.0)/p; u[i]=(y[i+1]-y[i])/(x[i+1]-x[i]) - (y[i]-y[i-1])/(x[i]-x[i-1]); u[i]=(6.0*u[i]/(x[i+1]-x[i-1])-sig*u[i-1])/p; } y2[n-1]=(un-qn*u[n-2])/(qn*y2[n-2]+1.0); for (k=n-2;k>=0;k--) y2[k]=y2[k]*y2[k+1]+u[k]; p_free(u); } void _splin2(float *xin, float *yin, float *image, float *deriv, long nx, long ny, long *nvalidx, float xout, float yout, float *res) { long j,m; long n=0; float *y2tmp,*yytmp; y2tmp = p_malloc(sizeof(float)*ny); yytmp = p_malloc(sizeof(float)*ny); for (j=0;j<=ny-1;j++) { m = nvalidx[j]; _splint(&xin[n],&image[n],&deriv[n],m,xout,&yytmp[j]); n += m; } _splinf(yin,yytmp,ny,y2tmp); _splint(yin,yytmp,y2tmp,ny,yout,res); p_free(y2tmp); p_free(yytmp); } void _splie2( float *xin, float *im, long nx, long ny, \ float *deriv, long *nvalidx) /* updated for XY faster indice */ { long j,m; long n=0; for (j=0;j<=ny-1;j++) { m = nvalidx[j]; _splinf(&xin[n],&im[n],m,&deriv[n]); n += m; } } void _spline2( float *xin, float *yin, float *im, float *deriv, long nx, long ny, \ float *xout, float *yout, long npt, long *nvalidx, float *res) { long i; for (i=0;i<=npt;i++) _splin2(xin,yin,im,deriv,nx,ny,nvalidx, \ xout[i],yout[i],&res[i]); } void _spline2grid( float *xin, float *yin, float *im, float *deriv, long nx, long ny, float *xout, float *yout, long nxout, long nyout, long *nvalidx, float *res) /* checked indices. runs good and fast. */ { long j,ii,jj; float *y2tmp,*yytmp; long n; long m; y2tmp = p_malloc(sizeof(float)*ny); yytmp = p_malloc(sizeof(float)*ny); for (ii=0;ii<=nxout-1;ii++) {/* loop on out x */ n=0; /* fill Y vector for xout(ii) */ for (j=0;j<=ny-1;j++) { m = nvalidx[j]; _splint(&xin[n],&im[n],&deriv[n],m,xout[ii],&yytmp[j]); n += m; } /* find second derivative */ _splinf(yin,yytmp,ny,y2tmp); /* find and fill interpolated out Y vector for this xout(ii) */ for (jj=0;jj<=nyout-1;jj++) { _splint(yin,yytmp,y2tmp,ny,yout[jj],&res[jj*nxout+ii]); } } p_free(y2tmp); p_free(yytmp); } yorick-imutil-0.5.7/bilinear.c0000644000076500001440000000415010730001576015641 0ustar frigautusers/* * Author: Francois Rigaut * * This file contains a number of utility functions, coded in C to gain * execution time. It addresses functionalities that are missing in * yorick, mostly concerning 2D image processing. * * Copyright (c) 2003-2007, Francois Rigaut * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details (to receive a copy of the GNU * General Public License, write to the Free Software Foundation, Inc., 675 * Mass Ave, Cambridge, MA 02139, USA). * */ void _bilinear(float *image, long nx, long ny, float *out, float *xout, float *yout, long nout, long skipoutside) { long i; long i0,j0,i1,j1,i00,i01,i10,i11; float wi,wj,w00,w01,w10,w11; /* Loop on indices of output image */ for (i=0;inx)|(yout[i]<1)|(yout[i]>ny))&skipoutside) continue; i0 = (long)(xout[i])-1; /* -1 because C indices are zero-based */ j0 = (long)(yout[i])-1; i1 = i0+1; j1 = j0+1; if (i0<0) i0=0; if (i0>(nx-1)) i0=nx-1; if (j0<0) j0=0; if (j0>(ny-1)) j0=ny-1; if (i1<0) i1=0; if (i1>(nx-1)) i1=nx-1; if (j1<0) j1=0; if (j1>(ny-1)) j1=ny-1; /* global index = col# + Ncolumns * row# */ i00 = i0+nx*j0; i10 = i1+nx*j0; i01 = i0+nx*j1; i11 = i1+nx*j1; /* Computes the weights for the 4 surrounding pixels */ wi = 1.0f-(xout[i]-(long)(xout[i])); wj = 1.0f-(yout[i]-(long)(yout[i])); w00 = wi*wj; w10 = (1-wi)*wj; w01 = wi*(1-wj); w11 = (1-wi)*(1-wj); /* Finaly, compute and integrate outphase */ out[i] = image[i00]*w00+image[i10]*w10+image[i01]*w01+image[i11]*w11; } } yorick-imutil-0.5.7/README0000644000076500001440000000422011504153473014572 0ustar frigautusersimutil plugin for Yorick: F.Rigaut, Nov2004. see file imutil.i for more details. version 0.5.6 1. Content: This plugin includes the following functions: func bilinear(image,arg1,arg2,grid=,minus_one=,outside=) bilinear interpolation on 2D arrays func spline2(image,arg1,arg2,grid=,minus_one=,outside=,mask=) 2D spline interpolation on 2d arrays func bin2d(in,binfact) resampling by neighbor averaging (binning) func cart2pol(image,&r,&theta,xc=,yc=,ntheta=,nr=,tor=,splin=,outside=) cartesian to polar coordinate mapping func clip(inarray,xmin,xmax) set min and max of array to said values func dist(dim,xc=,yc=) generate euclidian distance map func eclat(image) quadrant swap "a la FFT" func gaussdev(dims) generate random array with Gaussian statistic func poidev(vec) compute poisson statistic of input array func rotate2(image,angle,xc=,yc=,splin=,outside=) rotate 2D array using bilinear() or spline2() func sedgesort(vec) sort input vector func sedgemedian(vec) find median of input vector func cpc(im,fmin,fmax) return image clipped at fmin (fraction) and fmax. 2. Installation from source: see installation instructions in Makefile. Basically, you will need a C compiler and make/gnumake. You need yorick in your executable path. yorick -batch make.i make make check make install The install puts imutil.i in Y_SITE/i, the imutil.so library in Y_HOME/lib and the imutil_start.i in Y_SITE/i-start 3. History: 2010dec21 v0.5.7: modified Makefile for osx to create staticlib for linking with yao. 2010jun17 v0.5.6: poidev internals now use doubles 2010apr14 v0.5.5: Thibaut patch for round 2008mar10 v0.5.4: Added support for char, short, int in clip() 2005dec09 v0.5.1: updated the documents, README and info file. 2005dec01 v0.5 : bumped up to v0.5 2005nov08 v0.2.2: fixed local x in sedgesort 2005aug24 v0.2.1: added mask= keyword in spline2 to enable invalid data point in input array. 2005may18 v0.2 : Worked on compatibility with 64 bits. Check API for int/long mix up. Corrected a few. 21Nov2004 removed a call to img_read to read test image (introduced dependency), replaced by a restore. Nov2004 creation. yorick-imutil-0.5.7/check.i0000644000076500001440000002155510737010121015140 0ustar frigautusers/* * Author: Francois Rigaut * * check file for imutil * * Copyright (c) 2003-2007, Francois Rigaut * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details (to receive a copy of the GNU * General Public License, write to the Free Software Foundation, Inc., 675 * Mass Ave, Cambridge, MA 02139, USA). * */ require,"imutil.i"; require,"util_fr.i"; require,"random_et.i"; func chk_bilinear(void) { // removed the following lines as it introduced an // unnecessary dependancy to yorick-z // im = img_read("crane.jpg"); // im = float(im); // f = openb("crane.dat"); // restore,f,im; // close,f; dim = 512; sdim=32; im = gaussdev([2,dim,dim]); star = exp(-(dist(sdim)/2.)^2.); for (i=1;i<=1000;i++) { xs = long(dim/2.+gaussdev()*dim/5.); ys = long(dim/2.+gaussdev()*dim/5.); if (min(_(xs,ys)) < 1) continue; if (max(_(xs,ys)+sdim-1) > dim) continue; im(xs:xs+sdim-1,ys:ys+sdim-1) += star/(0.01+random()); } // im = float(jpeg_read("polarbear.jpg"))(sum,,)(,::-1); // palette,"gray.gp"; time = 100; // tests of speed: xi=1; yi=1; dim=100; nreb=2; sim = im(xi:xi+dim-1,yi:yi+dim-1); tic; tmp=bilinear(sim,nreb); eltime=tac()*1000.; write,format="bilinear(im,nreb) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n",dim,dim, nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.; dim = 512; tic; tmp=bilinear(im,nreb); eltime=tac()*1000.; write,format="bilinear(im,nreb) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n",dim,dim, nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.; xi=1; yi=1; dim=100; sim = im(xi:xi+dim-1,yi:yi+dim-1); xy = indices(100); tic; tmp=bilinear(sim,xy(,,1),xy(,,2)); eltime=tac()*1000.; write,format="bilinear(im,xarray,yarray) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n", dim,dim,nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.; //test of equality: if (allof(sim == bilinear(sim,1))) { write,"Checking that bilinear(im,1) = im ... Yes"; } else { error,"bilinear(im,1) != im"; } //displays and check of functionalities: xi=50; yi=200; dim=200; // xi=220; yi=300; dim=200; sim = im(xi:xi+dim-1,yi:yi+dim-1); // window,wait=1; palette,"earth.gp"; pli,sim; pltitle,"Original"; write,"Original"; //pause,time; fma; pli,bilinear(sim,2); pltitle,"bilinear(im,2)"; write,"bilinear(im,2)"; //pause,time; fma; pli,bilinear(sim,355,401); pltitle,"bilinear(im,355,401)"; write,"bilinear(im,355,401)"; //pause,time; fma; pli,bilinear(sim,401,355); pltitle,"bilinear(im,401,355)"; write,"bilinear(im,401,355)"; //pause,time; x = indgen(2*dim)/2.; y = indgen(2*dim)/2.; fma; pli,bilinear(sim,x,y,grid=1); pltitle,"bilinear(im,x,y,grid=1)"; write,"bilinear(im,x,y,grid=1)"; //pause,time; x = indgen(2*dim)/2.; y = indgen(2*dim)/3.; fma; plg,bilinear(im,x,y); pltitle,"bilinear(im,vector!_x,vector!_y)"; write,"bilinear(im,vector_x,vector_y)"; //pause,time; //speed test: // window,style="nobox.gs",wait=1; animate,1; for (i=10;i<=dim;i+=4) {fma;pli,bilinear(sim,i,i),cmin=0,cmax=255;} for (i=dim/2-1;i>=2;i-=4) { fma; pli,bilinear(sim(dim/2-i:dim/2+i,dim/2-i:dim/2+i),dim,dim),cmin=0,cmax=255; } animate,0; //pause,time; // check of other possibilities for errors: // window,style="work.gs"; tmp = bilinear(sim,10,300); tmp = bilinear(sim,300,10); tmp = bilinear(sim,300,300,minus_one=1); tmp = bilinear(sim,3,minus_one=1); xy = indices(512)-256; animate,1; for (a=0;a<=180;a+=20) { x = cos(a*pi/180)*xy(,,1) + sin(a*pi/180)*xy(,,2) + 256; y = -sin(a*pi/180)*xy(,,1) + cos(a*pi/180)*xy(,,2) + 256; fma; pli,bilinear(im,x,y,outside=10); } animate,0; //pause,time; } func chk_spline2(void) { // removed the following lines as it introduced an // unnecessary dependancy to yorick-z // im = img_read("crane.jpg"); // im = float(im); //f = openb("crane.dat"); //restore,f,im; //close,f; dim = 512; sdim=32; im = gaussdev([2,dim,dim]); star = exp(-(dist(sdim)/2.)^2.); for (i=1;i<=1000;i++) { xs = long(dim/2.+gaussdev()*dim/5.); ys = long(dim/2.+gaussdev()*dim/5.); if (min(_(xs,ys)) < 1) continue; if (max(_(xs,ys)+sdim-1) > dim) continue; im(xs:xs+sdim-1,ys:ys+sdim-1) += star/(0.01+random()); } // im = float(jpeg_read("polarbear.jpg"))(sum,,)(,::-1); // palette,"gray.gp"; time = 100; // tests of speed: xi=1; yi=1; dim=100; nreb=2; sim = im(xi:xi+dim-1,yi:yi+dim-1); tic; tmp=spline2(sim,nreb); eltime=tac()*1000.; write,format="spline2(im,nreb) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n",dim,dim, nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.; dim = 512; tic; tmp=spline2(im,nreb); eltime=tac()*1000.; write,format="spline2(im,nreb) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n",dim,dim, nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.; xi=1; yi=1; dim=100; sim = im(xi:xi+dim-1,yi:yi+dim-1); xy = indices(100); tic; tmp=spline2(sim,xy(,,1),xy(,,2)); eltime=tac()*1000.; write,format="spline2(im,xarray,yarray) (%d,%d) -> (%d,%d) : %.1fms, %.2fus/pixel\n", dim,dim,nreb*dim,nreb*dim,eltime,eltime*1000/(nreb*dim)^2.; //test of equality: if (allof(sim == spline2(sim,1))) { write,"Checking that spline2(im,1) = im ... Yes"; } else { error,"spline2(im,1) != im"; } //displays and check of functionalities: xi=50; yi=200; dim=200; // xi=220; yi=300; dim=200; sim = im(xi:xi+dim-1,yi:yi+dim-1); // window,wait=1; fma; pli,sim; pltitle,"Original"; write,"Original"; //pause,time; fma; pli,spline2(sim,2); pltitle,"spline2(im,2)"; write,"spline2(im,2)"; //pause,time; fma; pli,spline2(sim,355,401); pltitle,"spline2(im,355,401)"; write,"spline2(im,355,401)"; //pause,time; fma; pli,spline2(sim,401,355); pltitle,"spline2(im,401,355)"; write,"spline2(im,401,355)"; //pause,time; x = indgen(2*dim)/2.; y = indgen(2*dim)/2.; fma; pli,spline2(sim,x,y,grid=1); pltitle,"spline2(im,x,y,grid=1)"; write,"spline2(im,x,y,grid=1)"; //pause,time; return; x = indgen(2*dim)/2.; y = indgen(2*dim)/3.; fma; plg,spline2(im,x,y); pltitle,"spline2(im,vector!_x,vector!_y)"; write,"spline2(im,vector_x,vector_y)"; //pause,time; //speed test: // window,style="nobox.gs"; animate,1; for (i=10;i<=dim;i+=4) {fma;pli,spline2(sim,i,i),cmin=0,cmax=255;} for (i=dim/2-1;i>=2;i-=4) { fma; pli,spline2(sim(dim/2-i:dim/2+i,dim/2-i:dim/2+i),dim,dim),cmin=0,cmax=255; } animate,0; //pause,time; // check of other possibilities for errors: // window,style="work.gs"; tmp = spline2(sim,10,300); tmp = spline2(sim,300,10); tmp = spline2(sim,300,300,minus_one=1); tmp = spline2(sim,3,minus_one=1); xy = indices(50)-25; animate,1; for (a=0;a<=180;a+=20) { x = cos(a*pi/180)*xy(,,1) + sin(a*pi/180)*xy(,,2) + 100; y = -sin(a*pi/180)*xy(,,1) + cos(a*pi/180)*xy(,,2) + 100; fma; pli,spline2(sim,x,y); } animate,0; //pause,time; } window,wait=1; tic; g = dist(512); t1=tac(); tic; g = __dist(512); t2=tac(); write,format="Create dist(512): %fs (with interpreted function %f)\n",t1,t2; tic; gc = clip(g,10,50); t1=tac(); tic; gc = min(max(g,10),50); t2=tac(); write,format="clip image 512x512: %fs (with Buildin yorick function %f)\n",t1,t2; tic; gc = eclat(g); t1=tac(); tic; gc = roll(g); t2=tac(); write,format="Roll image 512x512: %fs (with Buildin yorick function %f)\n",t1,t2; tic; greb = bin2(g); t=tac(); write,format="rebin 512x512 -> 256x256: %fs\n",t; tic; x = gaussdev(100000); t1=tac(); tic; x = random_n(100000); t2=tac(); write,format="100000 normal random numbers: %fs (interpreted function %fs)\n",t1,t2; v = array(10,100000); tic; x = poidev(v); t1=tac(); tic; x = random_poisson(v); t2=tac(); write,format="Poisson of array(10,100000): %fs (interpreted function %fs)\n",t1,t2; //Interpolation tests chk_bilinear; chk_spline2; write,"Image interpolation tests OK"; // Sedgesort tests: n = 500000; write,format="Sorting %d numbers with sedgesort\n",n; a = long(10000*random(n)); tic; v = a(sort(a)); t1=tac(); tic; v = sedgesort(a); t2=tac(); write,format="Long: Regular sort: %fs / sedgesort: %fs\n",t1,t2; a = float(10000*random(n)); tic; v = a(sort(a)); t1=tac(); tic; v = sedgesort(a); t2=tac(); write,format="Float: Regular sort: %fs / sedgesort: %fs\n",t1,t2; a = double(10000*random(n)); tic; v = a(sort(a)); t1=tac(); tic; v = sedgesort(a); t2=tac(); write,format="Double: Regular sort: %fs / sedgesort: %fs\n",t1,t2; write,"All tests OK";