PixMatrix.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. WORD line_entries;
  49. BOOL lLine;
  50. BOOL rLine;
  51. WORD startpoint;
  52. WORD 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(WORD *image);
  70. void CorrectDBadLines(WORD *image);
  71. void CorrectDXLines(WORD *image, int nentry, int nstart, int nend);
  72. void CorrectDYLines(WORD *image, int nentry, int nstart, int nend);
  73. void MarkBadAdjacentPixels();
  74. void MarkBadPixels(int NumLines, PIX_MAP *New_Map);
  75. bool LoadBadPixelMap( const char *fileName );
  76. bool LoadLineMap( const char *fileName );
  77. bool LoadDLineMap( const char *fileName );
  78. bool MarkAdjacentLine( LINE_MAP *m_linemap);
  79. void CorrectLines(WORD* image);
  80. bool FreeLineMap(LINE_MAP *m_linemap);
  81. bool LoadBadPixelMapChar(char* data_char, bool bNew = FALSE);
  82. bool SaveBadPixelMap(const char *fileName);
  83. int SaveBadLineMap(const char *fileName);//自动坏线标记 by chen G N 2013-01-16
  84. void BadLineRecognize();//自动坏线标记 by chen G N 2013-01-23
  85. int LoadandCorrectBadLine( unsigned short *pImage, int GridDirection );//坏线的二次校正 by chen G N 2013-01-16
  86. bool AutoBadPixelMap(WORD *wImage);
  87. bool AutoBadPixelMap1(WORD *wImage);
  88. bool AutoBadPixelMap2(WORD *wImage);
  89. bool AutoBadPixelFixed(WORD *wImage, int threshold);
  90. void FreeBadPixelMap();
  91. void FreeDBadLineMap();
  92. void FreeBadNewPixelMap();
  93. bool CombineBadPixelMap();
  94. CPixMatrix(int width, int height,int woffset = 0, int hoffset = 0, int nPixelMax = 16383);
  95. void BeginAutoBadPixels(); //开始自动坏点校正
  96. void AddImageforBadPixels(WORD *wImage); //输入图像用于自动坏点校正
  97. bool AutoBadPointDec(unsigned short* lpDetail,int lWidth, int lHeight ,int Xoffset, int Yoffset,unsigned short*pmap);
  98. int GetAvg(unsigned short* pData,int Width, int Height ,int Xoffset, int Yoffset,int length);
  99. void EndAutoBadPixels(int nMode); //结束自动换点校正,-1,放弃;0,替换原有map;1,合并原有map
  100. bool StoreBadPixels(const char * charFilename,int nMode);
  101. void CorrectButCross(WORD* image);
  102. WORD *m_mapImg;
  103. //WORD *m_curImg;////////////////////////chenGN 2013.01.31
  104. //WORD *m_lastImg;////////////////////////chenGN 2013.01.31
  105. int m_curAvg;
  106. int m_lastAvg;
  107. int m_nLineData;//m_nLineData »µÏß×î´ó¶ÎÊý, zhaoyiru, 2017.05.09
  108. int *m_datalen;
  109. int Mean7(ushort_t *pImgData, int nWidth, int nHeight, int nXOffset, int nYOffset);
  110. double CalcGlbAvgPxlValueBySamp(unsigned short* pImgData, int nWidth, int nHeight, int nXOffset, int nYOffset);
  111. bool DetBadPxlByMF(ushort_t *pImgData, int nWidth, int nHeight, int nXOffset, int nYOffset, ushort_t *pMap);
  112. int BadGridLineCorrect( unsigned short *pImage);
  113. int BadGridLineCorrect1( unsigned short *pImage, int nLineDirection, int nEntries, int nStartPoint, int nEndPoint, int nWidth, int nHeight);
  114. int BadGridLineCorrect2( unsigned short *pImage, int nLineDirection, int nEntries, int nStartPoint, int nEndPoint, int nWidth, int nHeight);
  115. int BadGridLineCorrect3( unsigned short *pImage, int nLineDirection, int nEntries, int nStartPoint, int nEndPoint, int nWidth, int nHeight);
  116. int BadGridLineCorrect4( unsigned short *pImage, int nLineDirection, int nEntries, int nStartPoint, int nEndPoint, int nWidth, int nHeight);
  117. //bool CPixMatrix::DetBadPxlByMF(ushort_t *pImgData, int nWidth, int nHeight, int nXOffset, int nYOffset, ushort_t *pMap);
  118. private:
  119. static CPixMatrix* m_instance;
  120. PIX_MAP *m_NewMap;
  121. BAD_PIXEL_ENTRY *m_BadPixelMap;
  122. BAD_PIXEL_ENTRY *m_BadNewPixelMap; //store anothre badpixelmap, to combine with m_BadPixelMap;
  123. LINE_MAP *m_xLineMap;
  124. LINE_MAP *m_yLineMap;
  125. LINE_MAP2 *m_doubleLineMap;
  126. long *m_BadPixArray;
  127. int m_nWidth;
  128. int m_nHeight;
  129. int m_nWOffset;
  130. int m_nHOffset;
  131. int m_nLinePoint;//»µÏß×îСµãÊý, zhaoyiru, 2017.05.09
  132. char m_charFilename[256];
  133. unsigned short *m_TempImage;
  134. unsigned short *m_TempImage1;
  135. //int nWidth;
  136. //int nHeight;
  137. long *m_pBadPixNum;
  138. //int *m_datalen;
  139. int m_nPixelMax;//record the max pxiel value, for indicate the image pixel depth 16383, 65535
  140. };
  141. #endif // !defined(AFX_PIXMATRIX_H__A66061E3_ED45_4A21_ADDC_3A5F78FB36CE__INCLUDED_)