论文中图片加方框并且放大显示 matlab代码

本文为转载,原博客地址:http://blog.csdn.net/majinlei121/article/details/52334227

[cpp]  view plain  copy
  1. function I_rgb = ShowEnlargedRectangle(I, LeftUpPoint, RightBottomPoint, Enlargement_Factor, LineWidth, gap)  
  2. % example  I_rgb = ShowEnlargedRectangle(I, [10,20], [50,60], 1.5, 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. if ~exist('Enlargement_Factor','var')  
  17.     Enlargement_Factor = 1.5;  
  18. end  
  19.   
  20. if ~exist('gap','var') %离左下方距离  
  21.     gap = 1;  
  22. end  
  23.   
  24. %% 画矩形  
  25. I_rgb = DrawRectangle(I_rgb, LeftUpPoint, RightBottomPoint, LineWidth);  
  26.   
  27. %% 提取矩形区域内图像  
  28. UpRow = LeftUpPoint(1);  
  29. LeftColumn = LeftUpPoint(2);  
  30. BottomRow = RightBottomPoint(1);  
  31. RightColumn = RightBottomPoint(2);  
  32.   
  33. for i = 1 : size(I_rgb,3)  
  34.     Patch(:,:,i) = I_rgb(UpRow + LineWidth:BottomRow  - LineWidth,LeftColumn  + LineWidth:RightColumn  - LineWidth,i);   
  35. end  
  36.   
  37. %% 对提取到的区域进行放大  
  38. % Enlargement_Factor = 0.5;  
  39. Interpolation_Method = 'bilinear'; %bilinear,bicubic  
  40. Enlarged = imresize(Patch,Enlargement_Factor,Interpolation_Method);  
  41.   
  42. %% 对放大的区域进行显示  
  43. [m, n, c] = size(Enlarged);  
  44. [row, ~, ~] = size(I_rgb);  
  45. % EnlargedShowStartRow = row - 1 - LineWidth;  
  46. % EnlargedShowStartColumn = 2 + LineWidth;  
  47. for j = 1 : c  
  48. %     I_rgb(EnlargedShowStartRow - m + 1:EnlargedShowStartRow,EnlargedShowStartColumn:EnlargedShowStartColumn + n - 1,j) = Enlarged(:,:,j);   
  49. % end  
  50. EnlargedShowStartRow = row - gap - LineWidth;  
  51. EnlargedShowStartColumn = 1 + gap + LineWidth;  
  52. for j = 1 : c  
  53.     I_rgb(EnlargedShowStartRow - m + 1:EnlargedShowStartRow,EnlargedShowStartColumn:EnlargedShowStartColumn + n - 1,j) = Enlarged(:,:,j);   
  54. end  
  55.   
  56. %% 对放大显示后的区域画矩形  
  57. Point1 = [EnlargedShowStartRow - m + 1 - LineWidth,EnlargedShowStartColumn - LineWidth];  
  58. Point2 = [EnlargedShowStartRow + 1,EnlargedShowStartColumn + n -1 + 1];  
  59. I_rgb = DrawRectangle(I_rgb, Point1, Point2, LineWidth);  
  60.   
  61. end  
 
其中的DrawRectangle()函数见博文论文中图片加方框 matlab代码调用主体函数 
 

[cpp]  view plain  copy
  1. clear  
  2.   
  3. I = imread('lena.png');  
  4.   
  5. I1 = ShowEnlargedRectangle(I,[326,96],[368,138],3,2,2);  
  6. % figure;imshow(I);  
  7. figure;imshow(I1);</span>  

结果图像


  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值