【问题标题】:How to auto crop image region in imshow matlab如何在imshow matlab中自动裁剪图像区域
【发布时间】:2015-11-22 02:31:44
【问题描述】:

我使用下面的代码在一个图中显示了 6 张图片。但是,输出包含一些不需要的区域。我想将图像裁剪为下图。这意味着我想裁剪它,以便 ROI 包含我的 6 张照片。谢谢大家

这是我的代码

%% read images in a cell array
imgs = cell(6,1);
for i=1:6
    imgs{i} = imread( sprintf('AT3_1m4_%02d.tif',i) );
end

figure(1)
spaceH=0.01;spaceV=0.06;marTop=0.3;marBot=0.08; 
 padding=0.0;margin=0.0;marginL=0.0;
yoffset = 12;
set(gcf,'units','normalized','outerposition',[0 0 1 1])
% set(gcf,'color','w');
for i=1:6
    subaxis(2,3,i,'SpacingHoriz', spaceH, ...
            'SpacingVert',spaceV, 'PL',padding,'PR',padding,'mt',... 
            marTop,'mb',marBot,'ML',marginL,'MR',margin); title('Original'); 
   imshow(imgs{i},[0 255], 'InitialMag',90, 'Border','tight');
   xlb{i} = xlabel(['(' char(96+i) ')'],'FontSize', 16);
   xp = get(xlb{i}, 'position');
   xp(2) = xp(2) - yoffset; % update y-position
   set(xlb{i}, 'position', xp); % assign new position
end

这是我现在的照片

我想得到输出

【问题讨论】:

标签: matlab matlab-figure imshow


【解决方案1】:

你的问题是这个命令:

set(gcf,'units','normalized','outerposition',[0 0 1 1])

您将窗口强制设置为特定大小。

您可以执行以下操作: 1. 注释掉该行。 2. 执行你的代码。 3. 找出您的窗口需要多大的尺寸并将其放大。

【讨论】:

  • 不,我用它来放大我的身材。之后,我将裁剪不需要的区域。我的窗口大小未知。它会自动裁剪
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-27
  • 2016-12-05
  • 2012-09-12
  • 2012-07-31
相关资源
最近更新 更多