8 #include "PlusConfigure.h" 10 #include "igsioTrackedFrame.h" 11 #include "igsioVideoFrame.h" 12 #include "vtkIGSIOTrackedFrameList.h" 18 #include <vtkImageAccumulate.h> 19 #include <vtkImageCast.h> 20 #include <vtkImageDilateErode3D.h> 21 #include <vtkImageGaussianSmooth.h> 22 #include <vtkImageIslandRemoval2D.h> 23 #include <vtkImageSobel2D.h> 24 #include <vtkImageThreshold.h> 25 #include <vtkObjectFactory.h> 53 int dims[3] = { 0, 0, 0 };
54 inputImage->GetDimensions(dims);
56 unsigned char* vOutput = 0;
58 int distanceVerticalBuffer = 10;
59 int distanceHorizontalBuffer = 20;
61 std::vector<std::map<std::string, int> > boneAreas = this->
BoneAreasInfo;
69 for (
int areaIndex = boneAreas.size() - 1; areaIndex >= 0; --areaIndex)
71 std::map<std::string, int> currentArea = boneAreas.at(areaIndex);
74 boneHalfLen = ((currentArea[
"yMax"] - currentArea[
"yMin"]) + 1) / 2;
77 if (currentArea[
"yMax"] + distanceVerticalBuffer >= dims[1] - 1 || currentArea[
"yMin"] - distanceVerticalBuffer <= 0)
82 else if (boneHalfLen + currentArea[
"yMax"] >= dims[1] - 1 || (currentArea[
"yMin"] - 1) - boneHalfLen <= 0)
87 else if (currentArea[
"depth"] < distanceHorizontalBuffer || currentArea[
"depth"] > dims[0] - distanceHorizontalBuffer)
92 else if (currentArea[
"yMax"] - currentArea[
"yMin"] <= boneMinSize)
98 if (clearArea ==
true)
101 for (
int y = currentArea[
"yMax"];
y >= currentArea[
"yMin"]; --
y)
105 while (
x >= currentArea[
"xMin"] - this->BonePushBackPx &&
x >= 0 && foundBone ==
false)
107 vOutput = static_cast<unsigned char*>(inputImage->GetScalarPointer(
x,
y, 0));
112 for (
int removeBonex = std::max(0,
x - (this->
BoneOutlineDepthPx - 1)); removeBonex <
x; ++removeBonex)
114 vOutput = static_cast<unsigned char*>(inputImage->GetScalarPointer(removeBonex,
y, 0));
138 int dims[3] = { 0, 0, 0 };
139 inputImage->GetDimensions(dims);
142 unsigned char* vOutput = 0;
152 float aboveAvgShadow;
154 float belowAvgShadow;
156 std::map<std::string, int> currentArea;
157 std::vector<std::map<std::string, int> > boneAreas = this->
BoneAreasInfo;
162 for (
int areaIndex = boneAreas.size() - 1; areaIndex >= 0; --areaIndex)
164 currentArea = boneAreas.at(areaIndex);
170 boneLen = (currentArea[
"yMax"] - currentArea[
"yMin"]) + 1;
171 boneHalfLen = boneLen / 2;
172 boneArea = boneLen * currentArea[
"depth"];
175 for (
int y = currentArea[
"yMax"] + boneHalfLen;
y > currentArea[
"yMax"]; --
y)
177 for (
int x = dims[0] - 1;
x >= currentArea[
"depth"]; --
x)
179 vInput = (originalImage->GetScalarComponentAsFloat(
x,
y, 0, 0));
184 for (
int y = currentArea[
"yMax"];
y >= currentArea[
"yMin"]; --
y)
186 for (
int x = dims[0] - 1;
x >= currentArea[
"depth"]; --
x)
188 vInput = (originalImage->GetScalarComponentAsFloat(
x,
y, 0, 0));
193 for (
int y = currentArea[
"yMin"] - boneHalfLen;
y < currentArea[
"yMin"]; ++
y)
195 for (
int x = dims[0] - 1;
x >= currentArea[
"depth"]; --
x)
197 vInput = (originalImage->GetScalarComponentAsFloat(
x,
y, 0, 0));
203 aboveAvgShadow = aboveSum / (boneArea / 2);
204 areaAvgShadow = areaSum / boneArea;
205 belowAvgShadow = belowSum / (boneArea / 2);
208 if (aboveAvgShadow - areaAvgShadow <= areaAvgShadow / 2 || belowAvgShadow - areaAvgShadow <= areaAvgShadow / 2)
211 for (
int y = currentArea[
"yMax"];
y >= currentArea[
"yMin"]; --
y)
216 while (
x >= currentArea[
"xMin"] - this->BonePushBackPx &&
x >= 0 && foundBone ==
false)
218 vOutput = static_cast<unsigned char*>(inputImage->GetScalarPointer(
x,
y, 0));
224 for (
int removeBonex = std::max(0,
x - (this->
BoneOutlineDepthPx - 1)); removeBonex <
x; ++removeBonex)
226 vOutput = static_cast<unsigned char*>(inputImage->GetScalarPointer(removeBonex,
y, 0));
249 intermediateImage->DeepCopy(this->
LinesImage);
252 vtkSmartPointer<vtkImageData> originalImage = vtkSmartPointer<vtkImageData>::New();
253 originalImage->DeepCopy(intermediateImage);
Localize transverse process bone surfaces in ultrasound images.
void RemoveOffCameraBones(vtkSmartPointer< vtkImageData > inputImage)
vtkPlusTransverseProcessEnhancer()
vtkStandardNewMacro(vtkPlusTransverseProcessEnhancer)
virtual ~vtkPlusTransverseProcessEnhancer()
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual void PrintSelf(ostream &os, vtkIndent indent)
void AddIntermediateImage(char *fileNamePostfix, vtkSmartPointer< vtkImageData > image)
void CompareShadowAreas(vtkSmartPointer< vtkImageData > originalImage, vtkSmartPointer< vtkImageData > inputImage)
PlusStatus ProcessFrame(igsioTrackedFrame *inputFrame, igsioTrackedFrame *outputFrame)
Direction vectors of rods y
void LinearToFanImage(vtkSmartPointer< vtkImageData > inputImage, igsioTrackedFrame *outputFrame)
bool SaveIntermediateResults
vtkSmartPointer< vtkImageData > UnprocessedFrameToLinearImage(igsioTrackedFrame *inputFrame)
std::vector< std::map< std::string, int > > BoneAreasInfo
vtkSmartPointer< vtkImageData > LinesImage
void RemoveNoise(vtkSmartPointer< vtkImageData > inputImage)
Localize bone surfaces in ultrasound images.