[vtkusers] Sobel operator
orientation fu
fuzengliang435 at gmail.com
Wed Jun 27 06:40:25 EDT 2007
hello:
I want to extract object edges of CT(dicom format) image with sobel
operator. But there isn't any object edges at all when I render the
processed image. So there must be something wrong with my code or method. it
will be great if you can tell me what's wrong with my code.
thank you very much!
the code is as follow:
vtkDICOMImageReader *reader= vtkDICOMImageReader::New();
reader->SetFileName("ankle.dcm");
reader->Update();
int wide=reader->GetWidth();
int height=reader->GetHeight();
vtkImageData *imgData=reader->GetOutput();
double temp[10],temp1,temp2,sobelVal;
for(int i=1;i<wide-1;i++)//Sobel grads operator 3×3 model
for(int j=1;j<height-1;j++)
{
//点(i,j)八邻域的像素值
temp[1]=imgData->GetScalarComponentAsDouble(i-1,j-1,0,0);
temp[2]=imgData->GetScalarComponentAsDouble(i,j-1,0,0);
temp[3]=imgData->GetScalarComponentAsDouble(i+1,j-1,0,0);
temp[4]=imgData->GetScalarComponentAsDouble(i-1,j,0,0);
temp[6]=imgData->GetScalarComponentAsDouble(i+1,j,0,0);
temp[7]=imgData->GetScalarComponentAsDouble(i-1,j+1,0,0);
temp[8]=imgData->GetScalarComponentAsDouble(i,j+1,0,0);
temp[9]=imgData->GetScalarComponentAsDouble(i+1,j+1,0,0);
temp1=temp[7]+2*temp[8]+temp[9];temp1=temp1-temp[1]-temp[2]*2-temp[3];
temp2=temp[3]+2*temp[6]+temp[9];temp2=temp2-temp[1]-temp[4]*2-temp[7];
sobelVal=fabs(temp1)+fabs(temp2);//grads
imgData->SetScalarComponentFromDouble(i,j,0,0,sobelVal);
}
......//the following code renders the processed object
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070627/60d8bc77/attachment.htm>
More information about the vtkusers
mailing list