Picking every nth pixel on the x axis in images (matlab)

7 次查看(过去 30 天)
I am trying to pick every nth pixel in 600x600 image. I am not sure how to do and search as while doing it. I wrote a code and I didn't understand why it selects every 20th pixel in y axis but it selects every pixels in x axis. I wanna choose every pixel in y axis and every 20th pixel in x axis. How can I fix this? I attached the image result too.Here is my code;
I = imread('2.jpg');
I = imresize(I,[600,600]);
a = rgb2gray(I);
imshow(a);
[hy,hx]=find(a);
% choose every nth pixel
n = 20;
hxr = hx(1:n:end);
hyr = hy(1:n:end);
% plot
figure(10); clf;
imshow(I);
hold on;
plot(hxr,hyr,'r+');
% extract features + visualization object
[features,validPoints,visualization] = extractHOGFeatures(I,[hxr,hyr],'CellSize',[4 4]);
% show image and features
figure(20); clf;
imshow(I);
hold on;
plot(visualization,'Color','b');
% plot valid points for horizon
plot(validPoints(:,1),validPoints(:,2),'go');
  1 个评论
Adam
Adam 2017-7-18
Just flip around your x and y if that is your only problem. It is easy to get this wrong because you have to remember that array access is of the form
(row,column)
but row is actually equivalent to y and column to x so you need to index as (y,x) in that case.
Is that the only problem or are you saying you expect every 20th pixel in both x and y?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by