gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 7933d977: Warp: fix bug when using 'center' tr


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 7933d977: Warp: fix bug when using 'center' truncated image
Date: Wed, 5 Oct 2022 12:54:07 -0400 (EDT)

branch: master
commit 7933d97709bc6f1115b9613d59d756870800c458
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Warp: fix bug when using 'center' truncated image
    
    Until now, Warp used only the outer edges of the input image to measure the
    output image size automatically, and did not take the '--center' into
    account. For this reason, when a '--center' was defined, Warp would not
    calculate the size differently. In this case, size remains the same, but
    center is different; which leads to a truncated output image.
    
    With this commit, Warp calculates the output image size based on the given
    '--center' value. It will measure the difference between the given
    '--center' and the edges of the input image and pick the maximum
    value. This value is only half of the image size (i.e. distance from center
    to the furthest edge of the image), so it must be multiplied by two
    afterwards.
    
    This new method fixed this issue.
---
 lib/warp.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/warp.c b/lib/warp.c
index 52d5a1ae..8b8bae87 100644
--- a/lib/warp.c
+++ b/lib/warp.c
@@ -129,7 +129,7 @@ warp_wcsalign_init_output_from_params(gal_warp_wcsalign_t 
*wa)
   struct wcsprm *bwcs=NULL, *rwcs=NULL;
   gal_data_t *kcoords=NULL, *pcrn=NULL, *converted=NULL;
   double ocrpix[2], *xkcoords, *ykcoords, *x=NULL, *y=NULL;
-  double pmin[2]={DBL_MAX, DBL_MAX}, pmax[2]={-DBL_MAX, -DBL_MAX};
+  double pmin[2]={DBL_MAX, DBL_MAX}, pmax[2]={-DBL_MAX, -DBL_MAX}, tmp;
 
   /* Base WCS default parameters */
   double pc[4]={-1, 0, 0, 1};
@@ -199,11 +199,19 @@ warp_wcsalign_init_output_from_params(gal_warp_wcsalign_t 
*wa)
 
       /* Size must be odd so the image would have a center value. Also, the
          indices are swapped since number of columns defines the horizontal
-         part of the center and vice versa.  */
+         part of the center and vice versa. To calculate the output image
+         size, measure the difference between center and outermost edges of
+         the input image (in pixels). Since this is the distance from
+         center to the furthest edge of the image, the value must be
+         multiplied by two. */
       osize=gal_pointer_allocate(GAL_TYPE_SIZE_T, 2, 0,
                                  __func__, "osize");
-      osize[0] = WARP_NEXT_ODD(pmax[1]-pmin[1]);
-      osize[1] = WARP_NEXT_ODD(pmax[0]-pmin[0]);
+      tmp=2*fmax( fabs(ykcoords[4]-pmin[1]),
+                  fabs(ykcoords[4]-pmax[1]) );
+      osize[0] = WARP_NEXT_ODD(tmp);
+      tmp=2*fmax( fabs(xkcoords[4]-pmin[0]),
+                  fabs(xkcoords[4]-pmax[0]) );
+      osize[1] = WARP_NEXT_ODD(tmp);
     }
 
   /* Set the CRPIX value



reply via email to

[Prev in Thread] Current Thread [Next in Thread]