论文中图片加方框 matlab代码

2023-11-16

转自:http://blog.csdn.net/majinlei121/article/details/52334171

加方框函数

[cpp]  view plain  copy   在CODE上查看代码片 派生到我的代码片
  1. function I_rgb = DrawRectangle(I, LeftUpPoint, RightBottomPoint,LineWidth)  
  2. % example  I_rgb = ShowEnlargedRectangle(I, [10,20], [50,60], 1)  
  3.   
  4. if size(I,3)==1  
  5.     I_rgb(:,:,1) = I;  
  6.     I_rgb(:,:,2) = I;  
  7.     I_rgb(:,:,3) = I;  
  8. else  
  9.     I_rgb = I;  
  10. end  
  11.   
  12. if ~exist('LineWidth','var')  
  13.     LineWidth = 1;  
  14. end  
  15.   
  16. UpRow = LeftUpPoint(1);  
  17. LeftColumn = LeftUpPoint(2);  
  18. BottomRow = RightBottomPoint(1);  
  19. RightColumn = RightBottomPoint(2);  
  20.   
  21. % 上面线  
  22. I_rgb(UpRow:UpRow + LineWidth - 1,LeftColumn:RightColumn,1) = 255;  
  23. I_rgb(UpRow:UpRow + LineWidth - 1,LeftColumn:RightColumn,2) = 0;  
  24. I_rgb(UpRow:UpRow + LineWidth - 1,LeftColumn:RightColumn,3) = 0;  
  25. % 下面线  
  26. I_rgb(BottomRow:BottomRow + LineWidth - 1,LeftColumn:RightColumn,1) = 255;  
  27. I_rgb(BottomRow:BottomRow + LineWidth - 1,LeftColumn:RightColumn,2) = 0;  
  28. I_rgb(BottomRow:BottomRow + LineWidth - 1,LeftColumn:RightColumn,3) = 0;  
  29. % 左面线  
  30. I_rgb(UpRow:BottomRow,LeftColumn:LeftColumn + LineWidth - 1,1) = 255;  
  31. I_rgb(UpRow:BottomRow,LeftColumn:LeftColumn + LineWidth - 1,2) = 0;  
  32. I_rgb(UpRow:BottomRow,LeftColumn:LeftColumn + LineWidth - 1,3) = 0;  
  33. % 右面线  
  34. I_rgb(UpRow:BottomRow,RightColumn:RightColumn + LineWidth - 1,1) = 255;  
  35. I_rgb(UpRow:BottomRow,RightColumn:RightColumn + LineWidth - 1,2) = 0;  
  36. I_rgb(UpRow:BottomRow,RightColumn:RightColumn + LineWidth - 1,3) = 0;  
  37.   
  38. end  

调用

[cpp]  view plain  copy   在CODE上查看代码片 派生到我的代码片
  1. clear  
  2.   
  3. I = imread('lena.png');  
  4.   
  5. I1 = DrawRectangle(I,[100,100],[200,200]);  
  6. % figure;imshow(I);  
  7. figure;imshow(I1);  
  8. imwrite(I1,'lena_labeled.png');  
结果图像


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

论文中图片加方框 matlab代码 的相关文章

随机推荐