2012-02-06 60 views
0

我有一个图像IMG,我只想得到它的最后(20)列。 我的图像大小为500x500,我希望colums从480到500,行数保持不变。得到图像的最后20列:Matlab

+0

Downvote因为:你有什么尝试,没有研究工作。 – neuronet 2015-03-13 19:22:25

回答

1

试试这个:

cutImg = img(startrow:endrow,startcol:endcol); 

来自

Matlab Central

3

你可以把一些基本的数学和您的索引的end关键字。所以,你将有

smallerImage = rawImage(:, (end-20+1):end); 

作为colormapped(NxMx1)例如

load mandrill; %A colormapped (2d) Matlab demo image in the X variable 
figure; 
subplot(121) 
image(X) 
colormap(map) 
title('Full picture') 
subplot(122) 
smallX = X(: , (end-20+1):end); %This is the subsetting operation for a 2D image 
image(smallX) 
colormap(map) 
title('Rightmost 20 columns') 

的RGB例子(NxMx3)

imdata = imread('ngc6543a.jpg'); 
figure; 
subplot(121) 
image(imdata) 
colormap(map) 
title('Full picture') 
subplot(122) 
smallImData = imdata (: , (end-20+1):end , :); %This is the subsetting operation for an RGB image, note 3rd dimension colon 
image(smallImData) 
colormap(map) 
title('Rightmost 20 columns') 
0

如果你想利用最后n列,请使用:

A(:,end-n+1:end) 

对于第一个n列使用:

A(:,1:n)