From: M Ladderman on 11 Jun 2010 08:22 Hi.. imline() works indeed, but it is quite slow if you want to connect a lot of dots together. Is there any code that does the same faster, I use a loop to do the imline statement for each pixel pair and this takes a lot of time (minutes!!).. (I want to use it with ashape, see my earlier threads). Thanks a lot!! Cheers ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <bde45478-c1dd-4d6e-a03c-f4273fc58450(a)n15g2000yqf.googlegroups.com>... > On May 8, 5:38 pm, "jianbin gao" <gao...(a)hotmail.com> wrote: > > Hi, there > > Cound anybody tell me how to plot lines on a image? And the point, which belong to the lines, are the pixels point? > > -------------------------------------------------- > You can use line() to plot lines into the overlay of the image. > > If you want to "burn" lines into the image I think you can use > imline() with the createMask method - or just use the Bresenham line > method (Google it) and do it yourself.
From: Bruno Luong on 12 Jun 2010 07:38 I wrote a little function based on the fast mex interpolation in the previous thread. Hope it's fast enough for your need: function im = lineburning(im, x, y) % Burn the open polygon (x,y) into image im % Need nakeinterp1 mexfile: % http://www.mathworks.com/matlabcentral/newsreader/view_thread/258413 n = numel(x); m = size(im,1); for k=1:n-1 x1 = x(k); x2 = x(k+1); y1 = y(k); y2 = y(k+1); if abs(x2-x1)>abs(y2-y1) if x2<x1 [x1 x2] = deal(x2,x1); [y1 y2] = deal(y2,y1); end xi = (x1:x2).'; yi = round(nakeinterp1([x1; x2],[y1; y2], xi)); else if y2<y1 [x1 x2] = deal(x2,x1); [y1 y2] = deal(y2,y1); end yi = (y1:y2).'; xi = round(nakeinterp1([y1; y2], [x1; x2], yi)); end ind = (xi-1)*m+yi; % linear indexing % clip ind = ind(ind>=1 & ind <=numel(im)); im(ind) = 0; % Put the color you want here, or process RGB image as you like end %% % Test on command line % Data im=peaks(512)+7; x=ceil(512*rand(1,100)); y=ceil(512*rand(1,100)); % Burning tic imb = lineburning(im, x, y); toc % 0.007865 seconds. imagesc(imb); % Bruno
From: us on 12 Jun 2010 07:51 "jianbin gao" <gao_jb(a)hotmail.com> wrote in message <hs4lju$otp$1(a)fred.mathworks.com>... > Hi, there > Cound anybody tell me how to plot lines on a image? And the point, which belong to the lines, are the pixels point? a hint: - assuming you work with bitmaps... help imline; us
From: Bruno Luong on 12 Jun 2010 07:59 This is a pure Matlab version, slightly slower than MEX version: function im = lineburning(im, x, y) n = numel(x); m = size(im,1); for k=1:n-1 x1 = x(k); x2 = x(k+1); y1 = y(k); y2 = y(k+1); if abs(x2-x1)>abs(y2-y1) if x2<x1 [x1 x2] = deal(x2,x1); [y1 y2] = deal(y2,y1); end xi = (x1:x2).'; yi = linterp(x1, x2, y1, y2, xi); else if y2<y1 [x1 x2] = deal(x2,x1); [y1 y2] = deal(y2,y1); end yi = (y1:y2).'; xi = linterp(y1, y2, x1, x2, yi); end ind = (xi-1)*m+yi; ind = ind(ind>=1 & ind <=numel(im)); im(ind) = 0; % Put the color you want here end function y = linterp(x1, x2, y1, y2, x) y = round(y1+(x-x1)*((y2-y1)/(x2-x1))); end
From: ImageAnalyst on 12 Jun 2010 10:12
On Jun 11, 8:22 am, "M Ladderman" <mirresim...(a)gmail.com> wrote: > Hi.. > > imline() works indeed, but it is quite slow if you want to connect a lot of dots together. Is there any code that does the same faster, I use a loop to do the imline statement for each pixel pair and this takes a lot of time (minutes!!).. (I want to use it with ashape, see my earlier threads). Thanks a lot!! > > Cheers ----------------------------------------------------------------------------------------- Ladderman: Why don't you just use plot() - it will plot a polyline and it seems fast to me. It should be able to plot your shape in a small fraction of a second. By the way, there is no reason your line plotting with the line() or imline() function should take minutes - you're doing something wrong. And you never said whether having the line in the overlay is what you want, or if you need to change the underlying image pixel values. Can you answer that? ImageAnalyst |