00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 void COM2REAL (
00013 IMAGE *in,
00014 short option,
00015
00016
00017 IMAGE **out1,
00018
00019 IMAGE **out2
00020
00021
00022 ) { register short i, j, k, n;
00023 char msg[SLEN];
00024 double re, im;
00025
00026 if (TIMES) TIMING(T_COM2REAL);
00027 if (NAMES) {
00028 MESSAGE('I',"");
00029 MESSAGE('I',"COM2REAL");
00030 MESSAGE('I',"");
00031 sprintf(msg," Input image: %s",in->text);
00032 MESSAGE('I',msg);
00033 if (option == REIMAG) {
00034 MESSAGE('I'," Real and imaginary images computed");
00035 } else if (option == MAGPHA) {
00036 MESSAGE('I'," Magnitude and phase images computed");
00037 }
00038 MESSAGE('I',"");
00039 MESSAGE('I'," ...............");
00040 }
00041
00042
00043 if (!CHECKIMG(in)) {
00044 MESSAGE('E'," Can't identify image.");
00045 goto the_end;
00046 } else if (in->npix%2 != 0) {
00047 MESSAGE('E'," Number of pixels/line must be even.");
00048 goto the_end;
00049 } else if (option != REIMAG && option != MAGPHA) {
00050 MESSAGE('E'," Option must be either REIMAG or MAGPHA.");
00051 goto the_end;
00052 }
00053
00054
00055 if (!CHECKIMG(*out1)) GETMEM(in->nbnd,in->nlin,in->npix/2,out1);
00056 if (!*out1) goto the_end;
00057 if (!CHECKIMG(*out2)) GETMEM(in->nbnd,in->nlin,in->npix/2,out2);
00058 if (!*out2) goto the_end;
00059
00060 if (option == REIMAG) {
00061
00062 for (i=0; i<in->nbnd; i++) {
00063 for (j=0; j<in->nlin; j++) {
00064 for (k=0,n=0; k<in->npix/2; k+=1,n+=2) {
00065 (*out1)->data[i][j][k] = in->data[i][j][n];
00066 (*out2)->data[i][j][k] = in->data[i][j][n+1];
00067 }
00068 }
00069 }
00070 } else {
00071
00072 for (i=0; i<in->nbnd; i++) {
00073 for (j=0; j<in->nlin; j++) {
00074 for (k=0,n=0; k<in->npix/2; k+=1,n+=2) {
00075 re = (double)in->data[i][j][n];
00076 im = (double)in->data[i][j][n+1];
00077 (*out1)->data[i][j][k] = (PIXEL)sqrt((re*re + im*im));
00078 if (re == 0.0) {
00079 if (im > 0.0) {
00080 (*out2)->data[i][j][k] = (PIXEL)(PI/2.0);
00081 } else if (im < 0.0) {
00082 (*out2)->data[i][j][k] = (PIXEL)(-PI/2.0);
00083 } else {
00084 (*out2)->data[i][j][k] = (PIXEL)0.0;
00085 }
00086 } else {
00087 (*out2)->data[i][j][k] = (PIXEL)atan2(im,re);
00088 }
00089 }
00090 }
00091 }
00092 }
00093
00094 the_end:
00095 if (TIMES) TIMING(T_EXIT);
00096 }