how to crop image into overlapping patches

10 ビュー (過去 30 日間)
ghada sandoub
ghada sandoub 2020 年 5 月 6 日
コメント済み: Image Analyst 2020 年 6 月 28 日
i have an image of 720x680 and i want to extract overlapping patches. each patch has size of 16x16 and the overlapped pixels is 10. does anyone know how to do this in Matlab.
  1 件のコメント
darova
darova 2020 年 5 月 6 日
Please show the image

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2020 年 5 月 6 日
編集済み: Image Analyst 2020 年 5 月 6 日
Try this:
% Read in image.
rgbImage = imread('peppers.png');
h1 = subplot(2, 1, 1);
imshow(rgbImage);
hLine = yline(h1, 1, 'Color', 'y', 'LineWidth', 1);
h2 = subplot(2, 1, 2);
[rows, columns, numColorChannels] = size(rgbImage);
stepSize = 10;
subImageWidth = 16;
for row = 1 : stepSize : rows
row2 = min(row + subImageWidth - 1, rows);
% Put a yellow line over the full size image to let us know where it's at.
delete(hLine); % Delete old yellow line.
hLine = yline(h1, row2, 'Color', 'y', 'LineWidth', 1);
for col = 1 : stepSize : columns
col2 = min(col + subImageWidth - 1, columns);
subImage = rgbImage(row:row2, col:col2, :);
imshow(subImage);
drawnow;
end
end
  8 件のコメント
sotiraw sotiroglou
sotiraw sotiroglou 2020 年 6 月 28 日
I am trying to do the same with the sliding patches, but i need it to be done only for a part of an image. For example a region of image defined by a polygon inside image.
Lets say that somehow or someway we have this region by some coordinates of its nodes. For example if the region is a triangle , we have the cooedinates of the 3 nodes. If its a polygon , more.
How could i aply this only inside this polygon? I would appreciate your help
Image Analyst
Image Analyst 2020 年 6 月 28 日
Use poly2mask() to create a mask from the coordinates,
mask = poly2mask(x, y, rows, columns);
where rows and columns are for the small sliding patch, not the full sized image. Then multiply it by the image patch,
grayImage = grayImage .* uint8(mask);
or use indexing,
grayImage(~mask) = 0; % Erase outside of mask
or use bsxfun()
% Mask the image using bsxfun() function to multiply the mask by each channel individually. Works for gray scale as well as RGB Color images.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by