2017-04-17 79 views
0

我有一個二進制圖像,我找到了那些位置。我有x和y的位置。我從變量表中繪製出例如plot(1,94,'g +')。我選擇了每第60個像素。我想知道是否有可能有一個命令或代碼自己選擇每第n個像素而不是手動編寫?繪製或選擇二進制圖像中的第n個像素MATLAB

感謝

+1

你的意思是像 「提取每k個元素」[這裏](https://www.mathworks.com/公司/通訊/文章/矩陣索引功能於matlab.html)? – beaker

+0

我不知道它是否解壓。我只想繪製它們並在結果中顯示。我在二進制圖像中有一行,我想在其上顯示10個點。我手動寫了,但我正在尋找更實用的東西。 – cinemaniac

回答

0

只需使用索引1:n:end

% generate random binary image 
bw = rand(100) > 0.9; 
% locate all 1's 
[r,c] = find(bw); 
% choose every nth pixel 
n = 30; 
rr = r(1:n:end); 
cc = c(1:n:end); 
% plot 
imshow(bw,'InitialMagnification','fit'); 
hold on; 
plot(cc,rr,'r*'); 

enter image description here

+0

非常感謝。 [hy,hx] = find(bwi); imshow(bw);等一下; plot(hx,hy,'ro') %選擇每隔n個像素 n = 60; hx = x(1:n:end); hy = y(1:n:end); %陰謀 堅持; plot(hx,hy,'g *'); 我嘗試了我的代碼,但它只繪製了一點。我想找到十點。可能嗎? – cinemaniac

+0

do'hx = hx(1:n:end); hy = hy(1:n:結束);' – user2999345

+0

非常感謝!它的工作,有一個愉快的一天! – cinemaniac