Matlab 不可配置文件';s写等价物

Matlab 不可配置文件';s写等价物,matlab,Matlab,在MATLAB中,有一个函数可以从两点定义的直线下返回图像的强度分布 这个函数有没有写的等价物?也就是说,我想传递两个点(指定一条线)和一个像素值向量,以替换线下的一组像素。我知道一种难看的方法。这就是为什么: 使用imline创建一个由您的线组成的ROI。(首先使用imshow。) 从内联创建二进制ROI BW = createMask(H); 找到ROI的坐标 p = find(BW==1); 沿ROI指定的线将向量插入图像I I(p) = v; 为此,向量v的长度和ROI的长度必须相

在MATLAB中,有一个函数可以从两点定义的直线下返回图像的强度分布


这个函数有没有写的等价物?也就是说,我想传递两个点(指定一条线)和一个像素值向量,以替换线下的一组像素。

我知道一种难看的方法。这就是为什么:

使用imline创建一个由您的线组成的ROI。(首先使用imshow。)

从内联创建二进制ROI

BW = createMask(H);
找到ROI的坐标

p = find(BW==1);
沿ROI指定的线将向量插入图像I

I(p) = v;
为此,向量v的长度和ROI的长度必须相同。这并不总是容易的。要修复它,请插值v向量以获得正确的大小,也就是说,将最后一行替换为

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

您是否检查了源代码中的
不可配置文件
?它使用
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);
我基本上按照建议做了,但将
imline()
替换为手动查找底层像素。优点是没有显示可以带来一些速度优势的数字(在我的测试中约为0.5秒)


相关问题:谢谢,我最后做了一些非常类似的事情(见下面的答案)。
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);
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));