コード例 #1
0
ファイル: main_flip.c プロジェクト: rahlk/ece763
int main()
{
IFSIMG img1, inimg, outimg, outimg1, outimg2, dx_1, flux, dy_1, cdx_1, cdy_1, temp1, temp2, temp3, temp4, temp5, C1, C2, ones, diffIm;
int* len;
inimg=ifspin("angio.ifs"); // Specify the Image name here.
len = ifssiz(inimg);
int M = *(len+1);
int N = *(len+2);
outimg=ifscreate("float",len,IFS_CR_ALL,0);
outimg1=ifscreate("float",len,IFS_CR_ALL,0);
outimg2=ifscreate("float",len,IFS_CR_ALL,0);
img1=ifscreate("float",len,IFS_CR_ALL,0);
dx_1=ifscreate("float",len,IFS_CR_ALL,0);
dy_1=ifscreate("float",len,IFS_CR_ALL,0);
temp1=ifscreate("float",len,IFS_CR_ALL,0);
temp2=ifscreate("float",len,IFS_CR_ALL,0);
temp3=ifscreate("float",len,IFS_CR_ALL,0);
temp4=ifscreate("float",len,IFS_CR_ALL,0);
temp5=ifscreate("float",len,IFS_CR_ALL,0);
C1=ifscreate("float",len,IFS_CR_ALL,0);
ones=ifscreate("float",len,IFS_CR_ALL,0);
diffIm=ifscreate("float",len,IFS_CR_ALL,0);
C2=ifscreate("float",len,IFS_CR_ALL,0);
int i=0,j=0;
int flag=1;
// Convert image to float.

ifsany2any(inimg, img1);
while(i<M) {
    for(j=0; j<N; j++){
    ifsfpp(ones, i, j, 1);
    }
  i=i+1;
}

float alpha=0.001; // Specify Aplha
ifspot(ones,"ones.ifs");
diffIm=img1;
ifspot(diffIm, "temp.ifs"); // Save a copy for reference.

int iter=100;// Specify the number of iterations here.

flDoG(diffIm, dx_1, 1, 1, 0); //derivative in x
flDoG(diffIm, dy_1, 1, 1, 1); //derivative in y

// Compute the flux.
flmultv(dx_1, dx_1, temp1);
flmultv(dy_1, dy_1, temp2);
/*flsqrt(temp1, temp1);
flsqrt(temp2, temp2);*/

float k = 0.01;
// For conductance C = exp(-k*((|x'|+|y'|) )).

fladdv(temp1,temp2,temp3); // add them 
flsqrt(temp3, temp4); // take square root of the values 
flmults(temp4, temp5, -0.01); // multiply by k and negate the values 
flexp(temp5, C1); // compute C

// For conductance C = 1(1+k*(|x'|+|y'|)).
flmultv(temp3, temp3, temp3);
flsqrt(temp3, temp3);
fldivs(temp3, temp3, 0.5);
fladdv(temp3, ones, temp3);
ifspot(temp3,"Part1.ifs");
fldivv(ones, temp3, C2);
ifspot(C2,"flux1.ifs");

// Begin iteration

for(int i=0;i<iter;i++) {

flDoG(diffIm, dx_1, 1, 1, 0); //derivative in x
flDoG(diffIm, dy_1, 1, 1, 1); //derivative in y

// Use C2 flux equation.

flmultv(C2,dx_1,temp1); // Multiply with the first derivative
flmultv(C2,dy_1,temp2); // Multiply with the first derivative
flDoG(temp1, temp4, 1, 1, 0); //Differentiate again
flDoG(temp2, temp5, 1, 1, 1); //Differentiate again
fladdv(temp4, temp5, outimg); //Add the two
flmults(outimg, outimg1, alpha); //Multiply by alpha
fladdv(outimg1, diffIm, outimg2);
diffIm=outimg2; // Save the image... Repeat Iteration.
}
// End Iteration
ifspot(outimg2,"out.ifs"); // Save the image
}
コード例 #2
0
/*
This function (normally activated by the Apply button) attempts to apply the selected IFS function to the image in the left label and store the result in the right label.
*/
void IFSOperationViewer::applyOperation()
{
if(leftImageLabel->ifsImage == NULL)
{
return;
}

//If any of the parameter widgets are empty, set them to 0.0
for(int i=0; i<parameterLineEdits.size(); i++)
{
if(parameterLineEdits[i]->text() == QString(""))
{
parameterLineEdits[i]->setText("0.0");
}
}

//Get the parameters
std::vector<float> parameters;
for(int i=0; i<parameterLineEdits.size(); i++)
{
bool isOkay=false;
parameters.push_back(parameterLineEdits[i]->text().toFloat(&isOkay));
if(!isOkay)
{
fprintf(stderr, "One of the function parameters was non-numeric\n");
return;
}
}

std::string functionName = std::string(operationListBox->currentItem()->text().toAscii().constData());

//Allocate buffer space for the operation
IFSHDR *buffer = create2DFloatImage(ifsdimen(leftImageLabel->ifsImage, 0), ifsdimen(leftImageLabel->ifsImage, 1));
if(buffer == NULL)
{
//Image allocation failed
fprintf(stderr, "There was a failure when allocating space for the result of the operation\n");
return;
}

//Do the appropriate function given the current text value
/*
if(functionName == "flabsolute")
{
if(flabsolute(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else*/ if(functionName == "fladds")
{
if(fladds(leftImageLabel->ifsImage, buffer, parameters[0]) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flclip")
{
if(flclip(leftImageLabel->ifsImage, buffer, parameters[0]) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flcp")
{
if(flcp(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "fldivs")
{
if(fldivs(leftImageLabel->ifsImage, buffer, parameters[0]) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flexp")
{
if(flexp(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flln")
{
if(flln(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flmults")
{
if(flmults(leftImageLabel->ifsImage, buffer, parameters[0]) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flneg")
{
if(flneg(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flrec")
{
if(flrec(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flsq")
{
if(flsq(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flsqrt")
{
if(flsqrt(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flsubs")
{
if(flsubs(leftImageLabel->ifsImage, buffer, parameters[0]) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flthresh")
{
if(flthresh(leftImageLabel->ifsImage, buffer, parameters[0], parameters[1]) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flone_border")
{
if(flone_border(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flpad")
{
if(flpad(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flplanar")
{
if(flplanar(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flshx")
{
if(flshx(leftImageLabel->ifsImage, parameters[0], buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flshxy")
{
if(flshxy(leftImageLabel->ifsImage, parameters[0], parameters[1], buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flshy")
{
if(flshy(leftImageLabel->ifsImage, parameters[0], buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flzero_border")
{
if(flzero_border(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flDoG")
{
if(flDoG(leftImageLabel->ifsImage, buffer, parameters[0], parameters[1], parameters[2]) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "flGabor")
{
if(flGabor(leftImageLabel->ifsImage, buffer, parameters[0], parameters[1], parameters[2], parameters[3], parameters[4]) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "fldx")
{
if(fldx(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "fldx_back")
{
if(fldx_back(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "fldx_forw")
{
if(fldx_forw(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "fldxx")
{
if(fldxx(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "fldxy")
{
if(fldxy(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "fldy")
{
if(fldy(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "fldy_back")
{
if(fldy_back(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "fldy_forw")
{
if(fldy_forw(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else if(functionName == "fldyy")
{
if(fldyy(leftImageLabel->ifsImage, buffer) != functionDetailsMap[functionName].expectedReturnValue)
{
fprintf(stderr, "%s returned an error\n", functionName.c_str());
ifsfree(buffer, IFS_FR_ALL);
return;
}
}
else
{
fprintf(stderr, "Error, function operation %s not found\n", functionName.c_str());
}

rightImageLabel->setIFSImage(buffer);
}