PixMatrix.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // PixMatrix.h: interface for the CPixMatrix class.
  2. // 1.2.0.13. replace the AutoBadPointDec function
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_PIXMATRIX_H__A66061E3_ED45_4A21_ADDC_3A5F78FB36CE__INCLUDED_)
  5. #define AFX_PIXMATRIX_H__A66061E3_ED45_4A21_ADDC_3A5F78FB36CE__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. //#include "globle.h"
  10. #define NEIGHBOR_0 0x80000000L
  11. #define NEIGHBOR_1 0x40000000L
  12. #define NEIGHBOR_2 0x20000000L
  13. #define NEIGHBOR_3 0x10000000L
  14. #define NEIGHBOR_4 0x08000000L
  15. #define NEIGHBOR_5 0x04000000L
  16. #define NEIGHBOR_6 0x02000000L
  17. #define NEIGHBOR_7 0x01000000L
  18. /*
  19. #define MAX_BAD_PIXELS 200000L
  20. #define MAXI_BADPIX_COUNT 400000 // Big enough for the worst panel
  21. #define MAX_PIX_MAP_LINE 40000
  22. #define OFFSET_MASK 0xFFFF
  23. */
  24. #define MAX_BAD_PIXELS 1000000L
  25. #define MAXI_BADPIX_COUNT 400000 // Big enough for the worst panel
  26. #define MAX_PIX_MAP_LINE 40000
  27. #define OFFSET_MASK 0xFFFF
  28. //code begin 20100906
  29. typedef unsigned short ushort_t;
  30. //code end 20100906
  31. // Single bad pixel entry
  32. typedef struct
  33. {
  34. long num_entries;
  35. long *bad_pixel_num;
  36. } BAD_PIXEL_ENTRY;
  37. // Pointer to a single bad pixel entry
  38. typedef BAD_PIXEL_ENTRY *BAD_PIXEL_ENTRY_PTR;
  39. // Bad pixels contained within a single line
  40. typedef struct pix_map
  41. {
  42. long len;
  43. long *p_Pix;
  44. } PIX_MAP;
  45. //BadLine
  46. typedef struct line_map
  47. {
  48. unsigned short line_entries;
  49. bool lLine;
  50. bool rLine;
  51. unsigned short startpoint;
  52. unsigned short endpoint;
  53. line_map * nextline;
  54. } LINE_MAP;
  55. //BadLine2
  56. typedef struct line_map2
  57. {
  58. int nLineType;
  59. int line_entries;
  60. int startpoint;
  61. int endpoint;
  62. line_map2 * nextline;
  63. } LINE_MAP2;
  64. class CPixMatrix
  65. {
  66. public:
  67. static CPixMatrix* Instance();
  68. virtual ~CPixMatrix();
  69. void CorrectBadPixels(unsigned short *image);
  70. void CorrectDBadLines(unsigned short *image);
  71. int CalSpecX(unsigned short* image);
  72. int CalSpecY(unsigned short* image);
  73. void SwitchDBadLines(unsigned short *image);
  74. void CorrectDXLines(unsigned short *image, int nentry, int nstart, int nend);
  75. void SwitchDXLines(unsigned short *image, int nentry, int nstart, int nend, int spec);
  76. void CorrectDYLines(unsigned short *image, int nentry, int nstart, int nend);
  77. void SwitchDYLines(unsigned short *image, int nentry, int nstart, int nend, int spec);
  78. void MarkBadAdjacentPixels();
  79. void MarkBadPixels(int NumLines, PIX_MAP *New_Map);
  80. bool LoadBadPixelMap( const char *fileName );
  81. bool LoadLineMap( const char *fileName );
  82. bool LoadDLineMap( const char *fileName );
  83. bool MarkAdjacentLine( LINE_MAP *m_linemap);
  84. void CorrectLines(unsigned short* image);
  85. bool FreeLineMap(LINE_MAP *m_linemap);
  86. bool LoadBadPixelMapChar(char* data_char, bool bNew = false);
  87. bool SaveBadPixelMap(const char *fileName);
  88. int SaveBadLineMap(const char *fileName);//自动坏线标记 by chen G N 2013-01-16
  89. void BadLineRecognize();//自动坏线标记 by chen G N 2013-01-23
  90. int LoadandCorrectBadLine( unsigned short *pImage, int GridDirection );//坏线的二次校正 by chen G N 2013-01-16
  91. bool AutoBadPixelMap(unsigned short *wImage);
  92. bool AutoBadPixelMap1(unsigned short *wImage);
  93. bool AutoBadPixelMap2(unsigned short *wImage);
  94. bool AutoBadPixelFixed(unsigned short *wImage, int threshold);
  95. void FreeBadPixelMap();
  96. void FreeDBadLineMap();
  97. void FreeBadNewPixelMap();
  98. bool CombineBadPixelMap();
  99. CPixMatrix(int width, int height,int woffset = 0, int hoffset = 0, int nPixelMax = 16383);
  100. void BeginAutoBadPixels(); //开始自动坏点校正
  101. void AddImageforBadPixels(unsigned short *wImage); //输入图像用于自动坏点校正
  102. bool AutoBadPointDec(unsigned short* lpDetail,int lWidth, int lHeight ,int Xoffset, int Yoffset,unsigned short*pmap);
  103. int GetAvg(unsigned short* pData,int Width, int Height ,int Xoffset, int Yoffset,int length);
  104. void EndAutoBadPixels(int nMode); //结束自动换点校正,-1,放弃;0,替换原有map;1,合并原有map
  105. void StoreBadPixels(const char * charFilename,int nMode);
  106. void CorrectButCross(unsigned short* image);
  107. unsigned short *m_mapImg;
  108. //unsigned short *m_curImg;////////////////////////chenGN 2013.01.31
  109. //unsigned short *m_lastImg;////////////////////////chenGN 2013.01.31
  110. int m_curAvg;
  111. int m_lastAvg;
  112. int m_nLineData;//m_nLineData »µÏß×î´ó¶ÎÊý, zhaoyiru, 2017.05.09
  113. int *m_datalen;
  114. int Mean7(ushort_t *pImgData, int nWidth, int nHeight, int nXOffset, int nYOffset);
  115. double CalcGlbAvgPxlValueBySamp(unsigned short* pImgData, int nWidth, int nHeight, int nXOffset, int nYOffset);
  116. bool DetBadPxlByMF(ushort_t *pImgData, int nWidth, int nHeight, int nXOffset, int nYOffset, ushort_t *pMap);
  117. int BadGridLineCorrect( unsigned short *pImage);
  118. int BadGridLineCorrect1( unsigned short *pImage, int nLineDirection, int nEntries, int nStartPoint, int nEndPoint, int nWidth, int nHeight);
  119. int BadGridLineCorrect2( unsigned short *pImage, int nLineDirection, int nEntries, int nStartPoint, int nEndPoint, int nWidth, int nHeight);
  120. int BadGridLineCorrect3( unsigned short *pImage, int nLineDirection, int nEntries, int nStartPoint, int nEndPoint, int nWidth, int nHeight);
  121. int BadGridLineCorrect4( unsigned short *pImage, int nLineDirection, int nEntries, int nStartPoint, int nEndPoint, int nWidth, int nHeight);
  122. //bool CPixMatrix::DetBadPxlByMF(ushort_t *pImgData, int nWidth, int nHeight, int nXOffset, int nYOffset, ushort_t *pMap);
  123. private:
  124. static CPixMatrix* m_instance;
  125. PIX_MAP *m_NewMap;
  126. BAD_PIXEL_ENTRY *m_BadPixelMap;
  127. BAD_PIXEL_ENTRY *m_BadNewPixelMap; //store anothre badpixelmap, to combine with m_BadPixelMap;
  128. LINE_MAP *m_xLineMap;
  129. LINE_MAP *m_yLineMap;
  130. LINE_MAP2 *m_doubleLineMap;
  131. long *m_BadPixArray;
  132. int m_nWidth;
  133. int m_nHeight;
  134. int m_nWOffset;
  135. int m_nHOffset;
  136. int m_nLinePoint;//»µÏß×îСµãÊý, zhaoyiru, 2017.05.09
  137. char m_charFilename[256];
  138. unsigned short *m_TempImage;
  139. unsigned short *m_TempImage1;
  140. //int nWidth;
  141. //int nHeight;
  142. long *m_pBadPixNum;
  143. //int *m_datalen;
  144. int m_nPixelMax;//record the max pxiel value, for indicate the image pixel depth 16383, 65535
  145. };
  146. #endif // !defined(AFX_PIXMATRIX_H__A66061E3_ED45_4A21_ADDC_3A5F78FB36CE__INCLUDED_)