Equivalent equivalent

The MATLAB Image Processing Tool has improfileone that returns the profile of the image intensity from under the line defined by two points.

Is there a written equivalent of this function? That is, I would like to pass two points (indicate a line) and a vector of pixel values ​​to replace a bunch of pixels under the line.

+3
source share
3 answers

I basically did what Ghaul suggested , but replaced it imline()with a manual search for the underlying pixels. The advantage is that the figure is not shown, which brings some speed advantages (~ 0.5 s in my tests);

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));
0
source

. :

imline ROI, . ( imshow.)

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

ROI

BW = createMask(H);

ROI

p = find(BW==1);

, ROI

I(p) = v;

v ROI . . , v, ,

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

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);
+1
source

Source: https://habr.com/ru/post/1789483/


All Articles