-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub.cu
183 lines (150 loc) · 6.37 KB
/
sub.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright
//*****************************************************************************************************************
//*Declaration :This file is used for CV system. Beijing Neusoft Medical Equipment co., LTD all right reserved.
//*File Name : ImageSaver.h
//*Version : 1.0
//*Author : Mike
//*Company :Beijing Neusoft Medical Equipment co., LTD
//*Create Time : 2017-1-20
//*Modifier :
//*Modify Time :
//*Description :
//*****************************************************************************************************************
#include "SubtractElement.h"
#include "cuda_runtime.h"
#include <stdio.h>
#include "LoggerWrapper.h"
#include <math.h>
#include "Common.h"
#include "ElementParams.h"
#include "ImageFactory.h"
using namespace NeuSoftCv::Infrastructure::Common;
using namespace std;
using namespace NMS::CV::CoreLogic::Logger;
namespace NMS
{
namespace CV
{
namespace CoreLogic
{
namespace ImageProcessor
{
__global__ void SubtractKernel( const cudaPitchedPtr ptrLive, cudaPitchedPtr ptrMask, cudaPitchedPtr ptrResult,
int nHeight, int nWidth, float fOffset, float fLandmark, float fPixelMin, float fPixelMax )
{
int row_o=blockIdx.y*blockDim.y + threadIdx.y;
int col_o=blockIdx.x*blockDim.x + threadIdx.x;
if ( row_o >= nHeight || col_o >= nWidth )
{
return;
}
float* pLiveRow = (float*)( (char*)ptrLive.ptr + ptrLive.pitch*row_o );
float* pMaskRow = (float*)( (char*)ptrMask.ptr + ptrMask.pitch*row_o );
float* pResultRow = (float*)( (char*)ptrResult.ptr + ptrResult.pitch*row_o );
const float nLivePixel = pLiveRow[col_o];
const float nMaskPixel = pMaskRow[col_o];
float fDelta = (nLivePixel - nMaskPixel + fOffset);
// Modify Mantis bug: 0000406
// TODO(Mike): Need check Max and Min Pixel
float fRes = lroundf((1-fLandmark)*fDelta + fLandmark*nLivePixel );
if ( fRes < fPixelMin )
{
fRes = fPixelMin;
}
else if ( fRes > fPixelMax )
{
fRes = fPixelMax;
}
pResultRow[col_o] = fRes;
}
// Warning: This function can be deleted in future
__global__ void CombinationKernel( float* pLiveImage, float * pTraceImage, float *pMask1, float fOffset, float factor_AB, float factor_VC, float factor_CC, int nHeight, int nWidth );
CSubtractElement::CSubtractElement(void)
{
}
CSubtractElement::~CSubtractElement(void)
{
}
bool CSubtractElement::Init( )
{
bool bRet = false;
bRet = CBaseElement::Init( );
if( !bRet )
{
EngineerLog( ImageProcessorID.c_str(), "CSubtractElement::Prepare" );
return false;
}
return true;
}
bool CSubtractElement::Process( CDevImage<float>& clsInOutImage, PreProcParam* /*pPreParam = NULL*/, PostProcParam* pPostParam )
{
const bool bSubtractionSwitchIsOn =pPostParam->bSubtractionSwitchIsOn;
bool bRet = false;
CDevImage<float> clsMaskImage;
bRet = CImageFactory::GetInstance()->GetPixelShiftMaskImage( clsMaskImage );
if ( !bRet )
{
if( (clsInOutImage.stHeader.nDetectorID >= pPostParam->nMaskImageID) )
{
bRet = CImageFactory::GetInstance()->SavePixelShiftMaskImage( clsInOutImage );
if ( !bRet )
{
EngineerLog( ImageProcessorID.c_str(), "SaveMaskImage Failed" );
return false;
}
}
// Warning, Miss NOSUB_LUT
return true;
}
if( !bSubtractionSwitchIsOn )
{
return true;
}
if( clsInOutImage.stHeader.nWidth != clsMaskImage.stHeader.nWidth
|| clsInOutImage.stHeader.nHeight != clsMaskImage.stHeader.nHeight )
{
EngineerLog( ImageProcessorID.c_str(), "CSubtractElement::Process(), As image size not match: Live:%d*%d, Mask:%d*%d.",
clsInOutImage.stHeader.nHeight, clsInOutImage.stHeader.nWidth, clsMaskImage.stHeader.nHeight, clsMaskImage.stHeader.nWidth );
return false;
}
dim3 threadSquare( TILE_WIDTH, TILE_HEIGHT );
dim3 blockSquare( (clsInOutImage.stHeader.nWidth + TILE_WIDTH - 1)/TILE_WIDTH, (clsInOutImage.stHeader.nHeight + TILE_HEIGHT - 1) /TILE_HEIGHT );
float fOffset = CElementParams::GetInstance()->GetSubtractParam().fOffset;
float fLandscape = CElementParams::GetInstance()->GetSubtractParam().fLandscape;
cudaPitchedPtr ptrLive, ptrMask;
ptrLive.ptr = clsInOutImage.pImage;
ptrMask.ptr = clsMaskImage.pImage;
ptrMask.pitch = ptrLive.pitch = clsInOutImage.stHeader.nWidth*sizeof(float);
SubtractKernel<<<blockSquare, threadSquare>>>( ptrLive, ptrMask, ptrLive, \
clsInOutImage.stHeader.nHeight, clsInOutImage.stHeader.nWidth, fOffset, fLandscape, 0.f, 4095.f );
CImageFactory::GetInstance()->SaveTraceSubImage( clsInOutImage );
return true;
}
bool CSubtractElement::Process( CDevImage<float> clsLiveImage, CDevImage<float> clsMaskImage, CDevImage<float>& clsSubImage, float fPixelMin, float fPixelMax )
{
if( clsLiveImage.stHeader.nWidth != clsMaskImage.stHeader.nWidth
|| clsLiveImage.stHeader.nHeight != clsMaskImage.stHeader.nHeight )
{
EngineerLog( ImageProcessorID.c_str(), "CSubtractElement::Process(), As image size not match: Live:%d*%d, Mask:%d*%d.",
clsLiveImage.stHeader.nHeight, clsLiveImage.stHeader.nWidth, clsMaskImage.stHeader.nHeight, clsMaskImage.stHeader.nWidth );
return false;
}
clsSubImage.stHeader = clsLiveImage.stHeader;
dim3 threadSquare( TILE_WIDTH, TILE_HEIGHT );
dim3 blockSquare( (clsLiveImage.stHeader.nWidth + TILE_WIDTH - 1)/TILE_WIDTH, (clsLiveImage.stHeader.nHeight + TILE_HEIGHT - 1) /TILE_HEIGHT );
float fOffset = CElementParams::GetInstance()->GetSubtractParam().fOffset;
float fLandscape = CElementParams::GetInstance()->GetSubtractParam().fLandscape;
cudaPitchedPtr ptrLive, ptrMask, ptrSub;
ptrLive.ptr = clsLiveImage.pImage;
ptrMask.ptr = clsMaskImage.pImage;
ptrSub.ptr = clsSubImage.pImage;
ptrMask.pitch = ptrLive.pitch = ptrSub.pitch = clsLiveImage.stHeader.nWidth*sizeof(float);
SubtractKernel<<<blockSquare, threadSquare>>>( ptrLive, ptrMask, ptrSub, \
clsLiveImage.stHeader.nHeight, clsLiveImage.stHeader.nWidth, fOffset, fLandscape, fPixelMin, fPixelMax );
CImageFactory::GetInstance()->SaveTraceSubImage( clsLiveImage );
return true;
}
} // End ImageProcessor
} // End CoreLogic
} // End CV
} // End NMS