MATLAB: How to crop image into overlapping patches

cropping overlapping patchesMATLAB

i have an image of 720×680 and i want to extract overlapping patches. each patch has size of 16×16 and the overlapped pixels is 10. does anyone know how to do this in Matlab.

Best Answer

  • 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