在MATLAB的Image Processing Toolbox中有improfile
函數,該函數從兩點所定義的線條下方返回圖像的強度輪廓。人物形象的寫作等效
有沒有這樣寫等同於這個功能?也就是說,我想通過兩點(指定一條線)和一個像素值的矢量來替換線下的一組像素。
在MATLAB的Image Processing Toolbox中有improfile
函數,該函數從兩點所定義的線條下方返回圖像的強度輪廓。人物形象的寫作等效
有沒有這樣寫等同於這個功能?也就是說,我想通過兩點(指定一條線)和一個像素值的矢量來替換線下的一組像素。
我基本上做了什麼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));
我知道一個醜陋的方式來做到這一點。這是如何:
使用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));
最後一行你檢查的源代碼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);
謝謝,我確實在非常類似的東西結束(請參閱下面的答案)。 – 2011-05-10 16:00:53
相關的問題:http://stackoverflow.com/questions/1429210/get-all-pixel-coordinates-of-a-vector-inside-a-image – Amro 2011-02-02 17:29:18