2011-02-02 50 views
3

在MATLAB的Image Processing Toolbox中有improfile函数,该函数从两点所定义的线条下方返回图像的强度轮廓。人物形象的写作等效

有没有这样写等同于这个功能?也就是说,我想通过两点(指定一条线)和一个像素值的矢量来替换线下的一组像素。

+2

相关的问题:http://stackoverflow.com/questions/1429210/get-all-pixel-coordinates-of-a-vector-inside-a-image – Amro 2011-02-02 17:29:18

回答

0

我基本上做了什么Ghaul建议,但用手动查找底层像素替换了imline()。优点是没有显示一个数字,带来了一些速度的好处(在我的测试中约0.5秒);

dist_euc = norm(p1 - p2); 
n_pix = round(dist_euc*2); 
step = (p1 - p2)/n_pix; 
pix_coords = zeros(n_pix, 2); 
for cp = 0:n_pix 
    pix_coords(cp+1, :) = round(p2 + cp*step); 
end 
pix_inds = sub2ind(size(im), pix_coords(:,2), pix_coords(:,1)); 
pix_inds = unique(pix_inds); 
im(pix_inds) = interpft(prof, length(pix_inds)); 
2

我知道一个丑陋的方式来做到这一点。这是如何:

使用imline创建一个由您的行组成的ROI。 (第一使用imshow。)

imshow(I,[]) 
H = imline(gca,[x1 y1; x2 y2]); 

从在线创建二进制ROI

BW = createMask(H); 

找到ROI

p = find(BW==1); 

的坐标将您的载体导入图像I沿指定线路投资回报率

I(p) = v; 

为此,向量v的长度和ROI的长度必须相同。这并不容易。为了解决这个问题,你的插值V向量,以获得正确的尺寸,即,替换该

I(p) = interpft(v,length(p)); 
1

最后一行你检查的源代码improfile?它使用interp1,然后使用round来获得轮廓点的索引。

一个更简单的(也可能没有那么好)的选择是使用一个简单的参数方程为线和沿线段获得个人积分:

imageData =zeros(50,50); 
endPoints =[ 2 3; 40 27]; 

numberOfInterpolationPoints = 50; 
t=linspace(0,1,numberOfInterpolationPoints); 

% x and y of the points along this line 
x = 2 + t*(40-2); 
y = 3 + t*(27-3); 

% Round them to obtain valid indices 
profPoints = [x;y]'; 
profPoints = round(profPoints); 

% Keep only unique numbers 
profPoints = unique(profPoints,'rows'); 

% Convert to liner indices 
profPointsInd = sub2ind(size(imageData),profPoints(:,1), profPoints(:,2)); 

imageData(profPointsInd) = 1; 

imagesc(imageData); 
+0

谢谢,我确实在非常类似的东西结束(请参阅下面的答案)。 – 2011-05-10 16:00:53