|
Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 00003 #include <float.h> 00004 #include <cmath> 00005 00006 #include "ProcessByLine.h" 00007 #include "LineManager.h" 00008 00009 using namespace std; 00010 using namespace Isis; 00011 00012 void lowpass (Buffer &in, Buffer &out); 00013 void highpass (Buffer &in, Buffer &out); 00014 void bandpass (Buffer &in, Buffer &out); 00015 void bandstop (Buffer &in, Buffer &out); 00016 double radius (int x1, int y1, int x2, int y2); 00017 00018 int x, y, g; 00019 double d, dw; 00020 00021 void IsisMain() 00022 { 00023 ProcessByLine p; 00024 00025 UserInterface &ui = Application::GetUserInterface(); 00026 00027 // Initialize the input and output cubes 00028 Isis::Cube *icube = p.SetInputCube ("FROM"); 00029 00030 // get the center pixels coordinates 00031 x = (icube->Samples()+1)/2; 00032 y = (icube->Lines()+1)/2; 00033 00034 p.SetOutputCube ("TO"); 00035 00036 // Get the input values 00037 d = ui.GetDouble ("CUTOFF"); 00038 dw = ui.GetDouble("BANDWIDTH"); 00039 g = ui.GetInteger ("ORDER"); 00040 00041 // checks the type and runs the appropriate filter 00042 if (ui.GetString("TYPE") == "LOWPASS") { 00043 p.StartProcess(lowpass); 00044 } 00045 else if (ui.GetString("TYPE") == "HIGHPASS") { 00046 p.StartProcess(highpass); 00047 } 00048 else if (ui.GetString("TYPE") == "BANDPASS") { 00049 p.StartProcess(bandpass); 00050 } 00051 else if (ui.GetString("TYPE") == "BANDSTOP") { 00052 p.StartProcess(bandstop); 00053 } 00054 else { 00055 string msg = "Unknow value for TYPE [" + 00056 ui.GetString("TYPE") + "]"; 00057 throw iException::Message(iException::Programmer,msg,_FILEINFO_); 00058 } 00059 00060 p.EndProcess(); 00061 } 00062 00063 // Applies a lowpass filter to an image in the frequency domain. 00064 void lowpass (Buffer &in, Buffer &out) 00065 { 00066 double dist = 0.0; 00067 double B = 0.0; 00068 00069 for (int i=0; i<in.size(); i++) 00070 { 00071 dist = radius(in.Sample(i), in.Line(i), x, y); 00072 B = 1/(1+pow(dist/d, 2*g)); 00073 00074 out[i] = B*in[i]; 00075 } 00076 } 00077 00078 // Applies a highpass filter to an image in the frequency domain. 00079 void highpass (Buffer &in, Buffer &out) 00080 { 00081 double dist = 0.0; 00082 double B = 0.0; 00083 00084 for (int i=0; i<in.size(); i++) 00085 { 00086 dist = radius(in.Sample(i), in.Line(i), x, y); 00087 B = 1/(1+pow(d/dist, 2*g)); 00088 00089 out[i] = B*in[i]; 00090 } 00091 } 00092 00093 // Applies a bandpass filter to an image in the frequency domain. 00094 void bandpass (Buffer &in, Buffer &out) 00095 { 00096 double dist = 0.0; 00097 double B = 0.0; 00098 00099 for (int i=0; i<in.size(); i++) 00100 { 00101 dist = radius(in.Sample(i), in.Line(i), x, y); 00102 B = 1-1/(1+pow(dw*dist/(dist*dist-d*d), 2*g)); 00103 00104 out[i] = B*in[i]; 00105 } 00106 } 00107 00108 // Applies a bandstop filter to an image in the frequency domain. 00109 void bandstop (Buffer &in, Buffer &out) 00110 { 00111 double dist = 0.0; 00112 double B = 0.0; 00113 00114 for (int i=0; i<in.size(); i++) 00115 { 00116 dist = radius(in.Sample(i), in.Line(i), x, y); 00117 B = 1/(1+pow(dw*dist/(dist*dist-d*d), 2*g)); 00118 00119 out[i] = B*in[i]; 00120 } 00121 } 00122 00123 // measures the distance (or radius lenght) between the 00124 // point (x1, y1) and (x2,y2) 00125 double radius (int x1, int y1, int x2, int y2) 00126 { 00127 return sqrt((double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))); 00128 } 00129