细胞识别-图像处理_第1页
细胞识别-图像处理_第2页
细胞识别-图像处理_第3页
细胞识别-图像处理_第4页
细胞识别-图像处理_第5页
已阅读5页,还剩63页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、姓名:杜培明、王立Email:Email:安工大电信学院机器视觉机器视觉框图框图机器视觉机器视觉应用应用机器视觉机器视觉应用应用机器视觉机器视觉举例举例Reading of Serial NumbersReading of Serial Numbers机器视觉机器视觉举例举例Inspection of Saw BladesInspection of Saw Blades机器视觉机器视觉举例举例Surface InspectionSurface Inspection 机器视觉机器视觉举例举例3d_plane_reconstruction_with_stereo3d_plane_reconstru

2、ction_with_stereo机器视觉机器视觉举例举例冷轧带钢边部缺陷在线检测冷轧带钢边部缺陷在线检测细胞识别细胞识别原图原图24bit 细胞 个数 大小非细胞:细胞:1:Area:(169,200) Mean=1842:Area:(111,158) Mean=1273:Area:(153,193) Mean=1771:Area:(166,237) Mean=1982:Area:(144,226) Mean=1813:Area:(146,213) Mean=176细胞:细胞:非细胞:非细胞:结论:结论:利用H、S区分1:Area:(208,232) Mean=2162:Area:(22,7

3、4) Mean=553:Area:(153,185) Mean=1631:Area:(225,36) Mean=32:Area:(2,31) Mean=133:Area:(158,219) Mean=186RGBRGB:lpSrc=(unsigned char*)pDoc-m_pDib-m_lpImage + lLineBytes*(lHeight - 1 -point.y) + point.x*3;Rgb rgb;rgb.b=*lpSrc;rgb.g=*(lpSrc+1);rgb.r=*(lpSrc+2);struct Rgbunsigned char b;unsigned char g;u

4、nsigned char r;int gray=(int)(0.114*rgb.r+0.587*rgb.g+0.299*rgb.b);亮度:亮度:BGBGBRGRBRGRHBGBGBRGRBRGRHBGRBGRISBGRI2/122/12)()(2/)()(arccos360)()(2/)()(arccos),min()(3)(31RgbtoHsi(Rgb RgbtoHsi(Rgb * *pRgb, HSI pRgb, HSI * *pHsi)pHsi)R = (double) pRgb-r) / 255.0;G = (double) pRgb-g) / 255.0;B = (double)

5、pRgb-b) / 255.0;Sum = R + G + B;pHsi-Intensity = Sum / 3.0;MinValue = (R G) ? R : G;MinValue = (B G) ? R : G;MaxValue = (B MaxValue) ? B : MaxValue;if(pHsi-Intensity Saturation = ZERO_SATURATION;elsepHsi-Saturation = 1.0 - (3.0 * MinValue) / Sum;RgbtoHsi(Rgb RgbtoHsi(Rgb * *pRgb, HSI pRgb, HSI * *pH

6、si)pHsi)if(MinValue = MaxValue)pHsi-Hue = UNDEFINED_HUE;pHsi-Saturation = ZERO_SATURATION;return;TempDouble1 = (R - G) + (R - B) / 2.0);TempDouble2 = (R - G) * (R - G) + (R - B) * (G - B);Quotient = (TempDouble1 / sqrt(TempDouble2);Radians = acos(Quotient);Angle = Radians * DEGREES_PER_RADIAN;pHsi-H

7、ue =(BG)? 360.0 Angle : Angle;OnMouseMove(UINT nFlags, CPoint point)OnMouseMove(UINT nFlags, CPoint point)CString str=;if(pDoc-m_pDib-m_lpBMIH)unsigned char *lpSrc;if(point.x0) & (point.x0) & (point.ym_pDib-m_lpBMIH-biBitCount=8 ) lpSrc=(unsigned char*)pDoc-m_pDib-m_lpImage + lLineBytes*(lHeight - 1

8、 -point.y) + point.x; str.Format(L(x=%d y=%d)=%d,point.x,point.y,*lpSrc);OnMouseMove(UINT nFlags, CPoint point)OnMouseMove(UINT nFlags, CPoint point)else if(pDoc-m_pDib-m_lpBMIH-biBitCount=24 ) lpSrc=(unsigned char*)pDoc-m_pDib-m_lpImage + lLineBytes*(lHeight - 1 -point.y) + point.x*3;Rgb rgb;HSI Hs

9、i;rgb.b=*lpSrc;rgb.g=*(lpSrc+1);rgb.r=*(lpSrc+2);RgbtoHsi(&rgb, &Hsi);int gray=(int)(0.114*rgb.r+0.587*rgb.g+0.299*rgb.b);str.Format(LPos(%d %d) RGB(%d %d %d) Gray(%d) HSI(%4.1f %3.2f %3.2f-%d %d %d)“, point.x,point.y,rgb.r,rgb.g,rgb.b,gray, Hsi.Hue,Hsi.Saturation,Hsi.Intensity,(int)(Hsi.Hue/360.0*2

10、55.0),(int)(Hsi.Saturation*255.0),(int)( Hsi.Intensity*255.0);(CMainFrame*)AfxGetMainWnd()-m_wndStatusBar.SetPaneText(0,str);OnCellprocessMark()OnCellprocessMark()/不要取中心点,应该向远离背景方向偏移(小)double meanH=210.0*360/255;/you select double meanS=55.0/255;/you select double MarkDoor=0.09;double MayBeMarkDoor=

11、0.15;double x1=Hsi.Hue;/0360double x2=meanH;/近似if(x190) x1+=360;/归一化double y1=Hsi.Saturation;double y2=meanS;x1/=360;x2/=360;/0-1 double dis=DISTANCE(x1,y1,x2,y2);OnCellprocessMark()OnCellprocessMark()if(disMarkDoor)/Mark*lpSrc=0;*(lpSrc+1)=0;*(lpSrc+2)=255;/Redelse if(disMayBeMarkDoor)/may be Mark*

12、lpSrc=255;*(lpSrc+1)=0;*(lpSrc+2)=0;/Blue else/not Mark/maybe Markif(*lpSrc=0) *lpSrc=1;/Mark else if(*lpSrc=255) *lpSrc=254;/maybe mark if(*(lpSrc+1)=255) *(lpSrc+1)=254; /edge 1.Open Image 2.Add RgbtoHsiRgbtoHsi 3.Add OnMouseMove4.Select Threshold 5.Add Menu (&Mark) Do it yourself! We Can Help!boo

13、l MarkChg=true;while(MarkChg) MarkChg=false; for(int i = StartPoint.y; i = EndPoint.y; i+)for(int j =StartPoint.x; j m_pDib-m_lpImage + lLineBytes*(lHeight - 1 - i) + j*3; if(*lpSrc=255)/maybe Mark bool bProc=false; if(j0) if(*(lpSrc-3)=0) bProc=true; if(j0) if(*(lpSrc+lLineBytes)=0) bProc=true; if(

14、im_pDib-m_lpImage+ lLineBytes * (lHeight - 1 - i) + j*3;if(*(lpDst)=0 | *(lpDst)=255 )/Mark /Maybe Markdouble pixel9;lpSrc =lpNewDIBBits+ lLineBytes * (lHeight - 1 - i) + j*3;for(int m=-1;m2;m+)for(int n=-1;nedgeDoor)*(lpDst+1)=255;/edgeconst int M=5;bool bdelete;/filter for(int i = StartPoint.y+M;

15、i EndPoint.y-M; i+) for(int j =StartPoint.x+M; j m_pDib-m_lpImage+ lLineBytes * (lHeight - 1 - i) + j*3; if(*(lpDst+1)=255)/edge bdelete=true;for(int m=-M;m=M;m+) for(int n=-M;n=M;n+) if(m=-M | m=M | n=-M | n=M) if(*(lpDst+lLineBytes*m+n*3) | (*(lpDst+lLineBytes*m+n*3+1)=255)/noMark & no Edge bdelet

16、e=false; m=M+1;n=M+1;/out if(bdelete) *(lpDst+1)=0;/delete edgeMarked -Gray(128) Edge-Bright(240=0 xf0)OnCellprocessTwovalue():for(int i = 0; i lHeight; i+) for(int j = 0; j m_pDib-m_lpImage + lLineBytes*(lHeight - 1 - i) + j*3; lpDst =lpNewDIBBits + lNewLineBytes * (lHeight - 1 - i) + j;unsigned in

17、t v;v=0;if(*(lpSrc)=0)/Markv=TWOVALUE_H;if(*(lpSrc+1)v|=EDGEPOINT;/set edge*lpDst=(unsigned char)v;lLineBytes=lNewLineBytes;/ 复制转置后的图像delete pDoc-m_pDib;pDoc-m_pDib =new CDib(CSize(lNewLineBytes,lHeight ) ,8);lpSrc=(unsigned char*)pDoc-m_pDib-m_lpvColorTable;for(int i=0;im_pDib-m_lpImage, lpNewDIBBi

18、ts,lLineBytes*lHeight);delete lpNewDIBBits;Invalidate(true); 1.May be Mark to Mark 2.Get Edge information 3.TwoValue Do it yourself! We Can Help!OnCellprocessFillholes()OnCellprocessFillholes()/0 x7X-edge/0 x8X-Mark-not edge/0 xfX-Mark edge/0 xX1-visited/if no-marked & no-visitedif(!(*lpSrc & MARK_V

19、ISITED)/未访问过的黑点ProcessFillHoles(j,i);/line,col/edge area back/0 xfX-Mark edgeif(!(*lpSrc & MARKED)/非 Mark Point*lpSrc=0;/删除访问标志else if(*lpSrc & EDGEPOINT) /if marked & edge *lpSrc=0;ProcessFillHoles(int wd, int ht)ProcessFillHoles(int wd, int ht) stack s;vector v;/v save for fill holesconst int MAX_

20、HOLE=100;int xt,yt;xt=wd;yt=ht;s.push(CPoint(xt,yt);v.push_back(CPoint(xt,yt);unsigned char *lpSrc;lpSrc= (unsigned char *)pDoc-m_pDib-m_lpImage + lLineBytes* (lHeight-1-yt) + xt;*lpSrc|=VISITED;/vistiedbool bBorder=false;ProcessFillHoles(int wd, int ht)ProcessFillHoles(int wd, int ht)while(s.size()

21、/Add new members to stack/Above current pixellpSrc = (unsigned char *)pDoc-m_pDib-m_lpImage + lLineBytes* (lHeight-1-yt) + xt;if (ytStartPoint.y)/if no-marked & no-visitedif(!(*(lpSrc+lLineBytes) & MARK_VISITED)s.push(CPoint(xt,yt-1);v.push_back(CPoint(xt,yt-1);*(lpSrc+lLineBytes)|=VISITED;else bBor

22、der=true;/Below current pixel ProcessFillHoles(int wd, int ht)ProcessFillHoles(int wd, int ht)/Left of current pixel./Right of current pixelif (xtEndPoint.x)/if no-marked & no-visitedif(!(*(lpSrc+1) & MARK_VISITED)s.push(CPoint(xt+1,yt);v.push_back(CPoint(xt+1,yt);*(lpSrc+1)|=VISITED;else bBorder=tr

23、ue;/Retrieve current stack memberxt=s.top().x;yt=s.top().y;s.pop(); /Back to beginning of loopProcessFillHoles(int wd, int ht)ProcessFillHoles(int wd, int ht)/fill holeif (v.size()50)CString msg;msg.Format(L%d-(%d %d),v.size(),wd,ht);Invalidate(true);MessageBox(msg);for(UINT k=0;km_pDib-m_lpImage +

24、lLineBytes* (lHeight-1-yt) + xt;*lpSrc|=MARKED;OnCellprocessShrink()OnCellprocessShrink()/ 先去掉pre_shrink_count层皮GenEdge();for(int k=0;kpre_shrink_count;k+) for (int i=StartPoint.y;i=EndPoint.y;i+) for (int j=StartPoint.x;j=EndPoint.x;j+) / 去掉边界! if (*lpSrc & EDGEPOINT )(*lpSrc) &=NO_MARK;/marked=0;i

25、f (k%2=0)GenEdge4();elseGenEdge();GenEdge(void)/ GenEdge(void)/ 八方向生成边界八方向生成边界*lpSrc&=NO_EDGE_POINT;/no edgeif(*lpSrc & MARKED)/marked if(j = StartPoint.y | i = StartPoint.x | j = EndPoint.y | i = EndPoint.x)/ *lpSrc|=EDGEPOINT;else if / normal(!(*(lpSrc - lLineBytes - 1) & MARKED)&(*(lpSrc - lLineB

26、ytes) & MARKED)&(*(lpSrc - lLineBytes + 1) & MARKED)&(*(lpSrc - 1) & MARKED)&(*(lpSrc + 1) & MARKED)&(*(lpSrc + lLineBytes - 1) & MARKED)&(*(lpSrc + lLineBytes) & MARKED)&(*(lpSrc + lLineBytes + 1) & MARKED) *lpSrc|=EDGEPOINT;GenEdge4(void)GenEdge4(void) 1. OnCellprocessFillholes() OnCellprocessFill

27、holes() 2. ProcessFillHoles(int ProcessFillHoles(int wdwd, int , int htht) ) 3. OnCellprocessShrink() OnCellprocessShrink()Do it yourself! We Can Help! 4. GenEdge(void) GenEdge(void)、GenEdge4(void)GenEdge4(void) OnCellprocessFindcenter()OnCellprocessFindcenter()for (int k=0; bChanged ;k+) / 标志中心点的腐蚀

28、bChanged=false;/ 清除visited标志for (int j=StartPoint.y;jm_pDib-m_lpImage + lLineBytes* (lHeight-1-j) + StartPoint.x-1; for (int i=StartPoint.x;iStartPoint.y & jStartPoint.x & iEndPoint.x) / 最边上的不用处理 m_bFullEdge=true; if(*lpSrc & EDGEPOINT & !(*lpSrc & VISITED)/ 没有访问过的边界 if( !(*(lpSrc-1) & MARKED) & !(*

29、(lpSrc+1) & MARKED) & !(*(lpSrc+ lLineBytes) & MARKED) & !(*(lpSrc- lLineBytes) & MARKED) if (k=0) / 基本上这种是噪音continue;OnCellprocessFindcenter()OnCellprocessFindcenter()/ 孤立的点*lpSrc |=CENTERED;/ 保存一下CENTER_POINT信息pt.x=i;pt.y=j;pt.radius=k+pre_shrink_count+4;/circle adjust points_temp.push_back(pt);co

30、ntinue;elseMarkIt(i,j); / 判断是否需要保存/ 没有访问过标志了并且是边缘邻域/ 需要保存!if (m_bFullEdge) SaveIt(i,j,k+pre_shrink_count+3);/保存OnCellprocessFindcenter()OnCellprocessFindcenter()for (int j=StartPoint.y;jm_pDib-m_lpImage + lLineBytes* (lHeight-1-j) + StartPoint.x-1; for (int i=StartPoint.x;im_pDib-m_lpImage + lLineBy

31、tes* (lHeight-1-j) +i;*(lpSrc)|=VISITED;if (j=StartPoint.y | j=EndPoint.y | i=StartPoint.x | i=EndPoint.x) / 最边上的不用处理return;if ( !(*(lpSrc-1) & VISITED) &/ 没有访问过*(lpSrc-1) & MARKED )/ 标志了if (*(lpSrc-1) & EDGEPOINT )/ 并且是边缘MarkIt(i-1,j); / 左边elsem_bFullEdge=false;/ 右下SaveIt(int i, int j, int radius)S

32、aveIt(int i, int j, int radius)lpSrc=(unsigned char *)pDoc-m_pDib-m_lpImage + lLineBytes* (lHeight-1-j) +i;if (j=StartPoint.y | j=EndPoint.y | i=StartPoint.x | i=EndPoint.x) / 最边上的不用处理return;if(!(*lpSrc & CENTERED)CENTER_POINT pt;pt.x=i; pt.y=j;pt.radius=radius;points_temp.push_back(pt);/ marke curr

33、ent point*lpSrc|=CENTERED;/0 x02*lpSrc&=NO_VISITED;if ( *(lpSrc-1) & VISITED )SaveIt(i-1,j,radius); 1. OnCellprocessFindcenter() OnCellprocessFindcenter()2. MarkIt(int i, int j) MarkIt(int i, int j)Do it yourself! We Can Help!3. SaveIt(int i, int j, int radius) SaveIt(int i, int j, int radius)OnCell

34、processFindcenter()OnCellprocessFindcenter()if (jStartPoint.y & jStartPoint.x & iEndPoint.x) if (*lpSrc & CENTERED ) if ( !(*(lpSrc-1) & CENTERED) & !(*(lpSrc+1) & CENTERED) & !(*(lpSrc+lLineBytes) & CENTERED) &!(*(lpSrc-lLineBytes) & CENTERED) &!(*(lpSrc+lLineBytes-1) & CENTERED) &!(*(lpSrc+lLineBy

35、tes+1) & CENTERED) &!(*(lpSrc-lLineBytes-1) & CENTERED) &!(*(lpSrc-lLineBytes+1) & CENTERED) )/ 孤立的点保存pt.x=i; pt.y=j;for ( unsigned int n=0; nm_pDib-m_lpImage + lLineBytes* (lHeight-1-j) +i;if (j=StartPoint.y |j=EndPoint.y| i=StartPoint.x | i=EndPoint.x)return;tot_num+;tot_x+=i;tot_y+=j;*lpSrc&=NO_C

36、ENTER;for ( unsigned int n=0; nmax_radius)max_radius=points_temp.at(n).radius;break;if ( *(lpSrc-1) & CENTERED )CalcCenter Average(i-1,j);/相近的(不相连)中心点的处理(取半径大的)for (unsigned int i=0;iSelectObject(Redpen);for (unsigned int j=i+1;jpoints.size()-1;j+)int x=points.at(j).x;int y=points.at(j).y;if (abs(x0

37、-x)+abs(y0-y)10) / 相近 /display err position-delete pt=points.at(j);if(points.at(i).radiuspoints.at(j).radius)pt=points.at(i);points.at(i).x=(x+x0)/2;/savepoints.at(i).y=(y+y0)/2 points.at(i).radius=max(points.at(i).radius,points.at(j).radius)+2;/change point / 去掉潜在的错误(圆rSelectObject(Redpen1);bdelete

38、=false;for (unsigned int i=0;im_vCenterPoints.size();i+)/baord area processCENTER_POINT centerp;centerp=m_vCenterPoints.at(i);if(centerp.x-centerp.radius0)centerp.radius-=(centerp.x-centerp.radius);if(centerp.y-centerp.radiuslWidth-1)centerp.radius+=(centerp.x+centerp.radius-lWidth);if(centerp.y+centerp.radiuslHeight-1)centerp.radius+=(centerp.y+centerp.radius-lHeig

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论