发布于 2011-05-10 07:57:48
我基本上按照格洛的建议做了,但是用手动查找基础像素代替了imline()
。优点是没有显示数字,这会带来一些速度上的好处(在我的测试中~0.5s);
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));
发布于 2011-02-02 06:47:16
我知道一种丑陋的方法。如下所示:
使用内联创建由您的行组成的ROI。(先使用imshow。)
imshow(I,[])
H = imline(gca,[x1 y1; x2 y2]);
从内联创建二进制ROI
BW = createMask(H);
找到ROI的坐标
p = find(BW==1);
沿ROI指定的线将向量插入图像i中。
I(p) = v;
为了工作,向量v的长度和ROI的长度必须是相同的。这并不总是容易的。要修复它,将v向量内插以得到正确的大小,即用下面的代码替换最后一行
I(p) = interpft(v,length(p));
发布于 2011-02-02 07:53:59
你查过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);
https://stackoverflow.com/questions/4874298
复制