|
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 ProcessByLine p; 00023 00024 UserInterface &ui = Application::GetUserInterface(); 00025 00026 // Initialize the input and output cubes 00027 Isis::Cube *icube = p.SetInputCube("FROM"); 00028 00029 // get the center pixels coordinates 00030 x = (icube->sampleCount() + 1) / 2; 00031 y = (icube->lineCount() + 1) / 2; 00032 00033 p.SetOutputCube("TO"); 00034 00035 // Get the input values 00036 d = ui.GetDouble("CUTOFF"); 00037 dw = ui.GetDouble("BANDWIDTH"); 00038 g = ui.GetInteger("ORDER"); 00039 00040 // checks the type and runs the appropriate filter 00041 if(ui.GetString("TYPE") == "LOWPASS") { 00042 p.StartProcess(lowpass); 00043 } 00044 else if(ui.GetString("TYPE") == "HIGHPASS") { 00045 p.StartProcess(highpass); 00046 } 00047 else if(ui.GetString("TYPE") == "BANDPASS") { 00048 p.StartProcess(bandpass); 00049 } 00050 else if(ui.GetString("TYPE") == "BANDSTOP") { 00051 p.StartProcess(bandstop); 00052 } 00053 else { 00054 QString msg = "Unknow value for TYPE [" + 00055 ui.GetString("TYPE") + "]"; 00056 throw IException(IException::Programmer, msg, _FILEINFO_); 00057 } 00058 00059 p.EndProcess(); 00060 } 00061 00062 // Applies a lowpass filter to an image in the frequency domain. 00063 void lowpass(Buffer &in, Buffer &out) { 00064 double dist = 0.0; 00065 double B = 0.0; 00066 00067 for(int i = 0; i < in.size(); i++) { 00068 dist = radius(in.Sample(i), in.Line(i), x, y); 00069 B = 1 / (1 + pow(dist / d, 2 * g)); 00070 00071 out[i] = B * in[i]; 00072 } 00073 } 00074 00075 // Applies a highpass filter to an image in the frequency domain. 00076 void highpass(Buffer &in, Buffer &out) { 00077 double dist = 0.0; 00078 double B = 0.0; 00079 00080 for(int i = 0; i < in.size(); i++) { 00081 dist = radius(in.Sample(i), in.Line(i), x, y); 00082 B = 1 / (1 + pow(d / dist, 2 * g)); 00083 00084 out[i] = B * in[i]; 00085 } 00086 } 00087 00088 // Applies a bandpass filter to an image in the frequency domain. 00089 void bandpass(Buffer &in, Buffer &out) { 00090 double dist = 0.0; 00091 double B = 0.0; 00092 00093 for(int i = 0; i < in.size(); i++) { 00094 dist = radius(in.Sample(i), in.Line(i), x, y); 00095 B = 1 - 1 / (1 + pow(dw * dist / (dist * dist - d * d), 2 * g)); 00096 00097 out[i] = B * in[i]; 00098 } 00099 } 00100 00101 // Applies a bandstop filter to an image in the frequency domain. 00102 void bandstop(Buffer &in, Buffer &out) { 00103 double dist = 0.0; 00104 double B = 0.0; 00105 00106 for(int i = 0; i < in.size(); i++) { 00107 dist = radius(in.Sample(i), in.Line(i), x, y); 00108 B = 1 / (1 + pow(dw * dist / (dist * dist - d * d), 2 * g)); 00109 00110 out[i] = B * in[i]; 00111 } 00112 } 00113 00114 // measures the distance (or radius lenght) between the 00115 // point (x1, y1) and (x2,y2) 00116 double radius(int x1, int y1, int x2, int y2) { 00117 return sqrt((double)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))); 00118 } 00119