Obtain 2x2 regions in an image using sliding window
1 回表示 (過去 30 日間)
古いコメントを表示
Given an image,I would like to observe 2x2 regions of that image using sliding window.Notice that,as of now I am only interested in obsrving the pixels in that region and not with any further processing.
So its' like I start from the top left,in the 2x2 region there are a set of pixel values,then it goes to the next region and so on till the bottom right.
0 件のコメント
採用された回答
Walter Roberson
2021 年 7 月 31 日
If all you are doing is "observing" the pixels, then a double-nested loop is probably easiest; the time taken to "observe" them (display them as an image, or output them to a command line) would be much higher than any inefficiency due to looping.
If you were doing calculations, then there may be faster or more convenient methods.
3 件のコメント
Walter Roberson
2021 年 7 月 31 日
nfilter(I,(3,3),impixel)
will never be efficient. The impixel() part of it requires that the user select lines in the image interactively, and that is always going to be slow. And impixel() does not return a function handle, but the third parameter to nlfiter() must be a function handle. Perhaps you are using
nlfilter(I,[3,3],@impixel)
which would pass the 3 x 3 subset to impixel, but impixel would require a user interaction for every window processed.
その他の回答 (1 件)
Image Analyst
2021 年 7 月 31 日
Not sure you've got this solved or not after your last comment, but here is how I'd answer your original question:
rgbImage = imread('peppers.png');
[rows, columns, numColorChannels] = size(rgbImage)
for row = 1 : rows-1
for col = 1 : columns - 1
subImage = rgbImage(row:row+1, col:col+1, :);
imshow(subImage, 'InitialMagnification', 70000, 'XData', [col, col+1], 'YData', [row, row+1]);
axis('on', 'image');
pause(0.25);
caption = sprintf('Showing rows %d-%d, columns %d-%d.\n', row, row+1, col, col+1);
xlabel(caption);
fprintf('%s\n', caption);
drawnow;
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Computer Vision with Simulink についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!