Changeset 20894
- Timestamp:
- 10/07/08 14:10:50 (2 months ago)
- Location:
- lang/cpluspluscli/OpenCvSharp/trunk/OpenCvSharp
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/cpluspluscli/OpenCvSharp/trunk/OpenCvSharp/CvArr.cpp
r17367 r20894 395 395 } 396 396 #pragma endregion 397 #pragma region EqualizeHist 398 /// <summary> 399 /// インプレースモード(src = dst)でグレースケール画像のヒストグラムを均一化する (cvEqualizeHist相当). 400 /// 輝度を均一化し,画像のコントラストを上げる. 401 /// </summary> 402 void CvArr::EqualizeHist( void ) 403 { 404 OpenCV::cvEqualizeHist(this, this); 405 } 406 /// <summary> 407 /// グレースケール画像のヒストグラムを均一化する (cvEqualizeHist相当).] 408 /// 輝度を均一化し,画像のコントラストを上げる. 409 /// </summary> 410 /// <param name="dst">出力画像.srcと同じサイズ, 同じデータタイプ.</param> 411 void CvArr::EqualizeHist( N::CvArr^ dst ) 412 { 413 OpenCV::cvEqualizeHist(this, dst); 414 } 415 #pragma endregion 397 416 #pragma region FillConvexPoly 398 417 /// <summary> -
lang/cpluspluscli/OpenCvSharp/trunk/OpenCvSharp/CvArr.h
r17367 r20894 229 229 virtual void Ellipse( N::CvPoint center, N::CvSize axes, Double angle, Double start_angle, Double end_angle, CvColor color, Int32 thickness, LineType line_type ); 230 230 virtual void Ellipse( N::CvPoint center, N::CvSize axes, Double angle, Double start_angle, Double end_angle, CvColor color, Int32 thickness, LineType line_type, Int32 shift ); 231 virtual void EqualizeHist( void ); 232 virtual void EqualizeHist( N::CvArr^ dst ); 231 233 virtual void FillConvexPoly( array<N::CvPoint>^ pts, N::CvColor color ); 232 234 virtual void FillConvexPoly( array<N::CvPoint>^ pts, N::CvColor color, LineType line_type ); -
lang/cpluspluscli/OpenCvSharp/trunk/OpenCvSharp/Extras.cpp
r20858 r20894 40 40 } 41 41 42 dst->Zero(); 42 N::IplImage^ gray = src->Clone(); 43 gray->EqualizeHist(); 44 43 45 Byte* p = dst->ImageDataPtr; 44 for (int y = 0; y < src->Height; y++) { 45 for (int x = 0; x < src->Width; x++) { 46 double m = Mean(src, x, y, size); 47 double s = StdDev(src, x, y, size, m); 48 if(Math::Abs(s) > 0.1){ 49 s = s; 50 } 46 double m, s; 47 48 for (int y = 0; y < gray->Height; y++) { 49 for (int x = 0; x < gray->Width; x++) { 50 MeanStddev(gray, x, y, size, &m, &s); 51 51 int offset = (dst->WidthStep * y) + x; 52 52 p[offset] = (Byte)(m + k*s); … … 85 85 } 86 86 87 dst->Zero(); 87 N::IplImage^ gray = src->Clone(); 88 gray->EqualizeHist(); 89 88 90 Byte* p = dst->ImageDataPtr; 89 for (int y = 0; y < src->Height; y++) { 90 for (int x = 0; x < src->Width; x++) { 91 double m = Mean(src, x, y, size); 92 double s = StdDev(src, x, y, size, m); 91 double m, s; 92 int offset; 93 93 94 int offset = (dst->WidthStep * y) + x; 94 for (int y = 0; y < gray->Height; y++) { 95 for (int x = 0; x < gray->Width; x++) { 96 MeanStddev(gray, x, y, size, &m, &s); 97 offset = (dst->WidthStep * y) + x; 95 98 p[offset] = (Byte)(m + (1 + k*(s/r - 1))); 96 99 } … … 99 102 100 103 /// <summary> 101 /// ���ډ��̎�f�̕��ϒl��߂� /// </summary> 102 Double Extras::Mean(N::IplImage^ img, Int32 x, Int32 y, Int32 size) 104 /// ���ډ��̎�f�̕��ϒl�ƕW������߂� /// </summary> 105 /// <param name="r">�W��</param> 106 void Extras::MeanStddev(N::IplImage^ img, Int32 x, Int32 y, Int32 size, Double* mean, Double* stddev) 103 107 { 104 108 int count = 0; 105 int init_x = x - size + (size/2+1);106 int init_y = y - size + (size/2+1);107 109 int sum = 0; 110 int sum2 = 0; 108 111 Byte* p = img->ImageDataPtr; 112 int xxx, yyy; 113 int size2 = size / 2; 114 int widthStep = img->Width; 115 Byte v; 109 116 110 117 for(int xx = 0; xx<size; xx++){ 111 118 for(int yy = 0; yy<size; yy++){ 112 int xxx = x + xx - size/2;113 int yyy = y + yy - size/2;119 xxx = x + xx - size2; 120 yyy = y + yy - size2; 114 121 if(xxx < 0 || xxx >= img->Width || yyy < 0 || yyy >= img->Height){ 115 122 continue; 116 123 } 117 sum += p[img->WidthStep * yyy + xxx]; 124 v = p[widthStep * yyy + xxx]; 125 sum += v; 126 sum2 += v * v; 118 127 count++; 119 128 } 120 129 } 121 122 return (double)sum / count; 123 } 124 125 /// <summary> 126 /// ���ډ��̎�f�̕W������߂� /// </summary> 127 Double Extras::StdDev(N::IplImage^ img, Int32 x, Int32 y, Int32 size, Double mean) 128 { 129 int count = 0; 130 int init_x = x - size + (size/2+1); 131 int init_y = y - size + (size/2+1); 132 double sum = 0; 133 Byte* p = img->ImageDataPtr; 134 135 for(int xx = 0; xx<size; xx++){ 136 for(int yy = 0; yy<size; yy++){ 137 int xxx = x + xx - size/2; 138 int yyy = y + yy - size/2; 139 if(xxx < 0 || xxx >= img->Width || yyy < 0 || yyy >= img->Height){ 140 continue; 141 } 142 Byte v = p[img->WidthStep * yyy + xxx]; 143 sum += Math::Pow(v - mean, 2); 144 count++; 145 } 146 } 147 double variance = sum / count; 148 return Math::Sqrt(variance); 130 *mean = (double)sum / count; 131 double var = (double)sum2 / count - (*mean)*(*mean); 132 if(var < 0.0) var = 0.0; 133 *stddev = sqrt(var); 149 134 } 150 135 -
lang/cpluspluscli/OpenCvSharp/trunk/OpenCvSharp/Extras.h
r20858 r20894 32 32 33 33 private: 34 static Double Mean(N::IplImage^ img, Int32 x, Int32 y, Int32 size); 35 static Double StdDev(N::IplImage^ img, Int32 x, Int32 y, Int32 size, Double mean); 34 static void MeanStddev(N::IplImage^ img, Int32 x, Int32 y, Int32 size, Double* mean, Double* stddev); 36 35 }; 37 36 -
lang/cpluspluscli/OpenCvSharp/trunk/OpenCvSharp/OpenCV.cpp
r20286 r20894 2307 2307 CHECK_NULL(fs); 2308 2308 ::cvEndWriteStruct(fs->Ptr); 2309 } 2310 #pragma endregion 2311 #pragma region cvEqualizeHist 2312 /// <summary> 2313 /// グレースケール画像のヒストグラムを均一化する.輝度を均一化し,画像のコントラストを上げる. 2314 /// </summary> 2315 /// <param name="src">入力画像.8ビットシングルチャンネル. </param> 2316 /// <param name="dst">出力画像.srcと同じサイズ, 同じデータタイプ.</param> 2317 void OpenCV::cvEqualizeHist( N::CvArr^ src, N::CvArr^ dst ) 2318 { 2319 CHECK_NULL(src); 2320 CHECK_NULL(dst); 2321 ::cvEqualizeHist(src->Ptr, dst->Ptr); 2309 2322 } 2310 2323 #pragma endregion -
lang/cpluspluscli/OpenCvSharp/trunk/OpenCvSharp/OpenCV.h
r20286 r20894 187 187 static void cvEllipse( N::CvArr^ img, N::CvPoint center, N::CvSize axes, Double angle, Double start_angle, Double end_angle, CvColor color, Int32 thickness, LineType line_type, Int32 shift ); 188 188 static void cvEndWriteStruct( N::CvFileStorage^ fs ); 189 static void cvEqualizeHist( N::CvArr^ src, N::CvArr^ dst ); 189 190 static void cvErode( N::CvArr^ src, N::CvArr^ dst ); 190 191 static void cvErode( N::CvArr^ src, N::CvArr^ dst, N::IplConvKernel^ element );
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)