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

4 views (last 30 days)
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 Comment
Adam
Adam on 18 Jul 2017
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?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!