How to convert image into overlapping blocks?

조회 수: 1 (최근 30일)
h612
h612 2017년 4월 5일
편집: h612 2017년 4월 6일
I'm trying to extract overlapping patches (size of patch 257x257) of an image with a 50% overlap. I wrote this code. Not sure what went wrong>
a = i
mread('...');
[row col]=size(a)
for i=1:256:col-123
for j = 1:256:row-123
if j~=1&&i~=1
block=a(j-123:j+123,i-123:i+123)
else
block=a(j:j+123,i:i+123)
end
imshow(block)
end
end

답변 (1개)

Image Analyst
Image Analyst 2017년 4월 5일
Assuming you got the 50% overlapping blocks, I'm not sure what you want to do with them. Why not just use blockproc() where you can specify a jumpsize of less than the window size to get overlapping?
  댓글 수: 1
h612
h612 2017년 4월 6일
편집: h612 2017년 4월 6일
I've already tried with blockproc.
  • However, it doesn't add neighboring pixels as it is, instead add an overlap of 0s on the boundry- of the full image.
  • Also the resulting blocks that arent 257x257, it doesn't interpolate them etc to make it 257x257.
Here is what I tried
function cropSaveBlock(bs)
subBlockRegion =(bs.data(:,:));
fileName = [strrep(num2str(bs.location),' ','_') '.jpg'];
imwrite(subBlockRegion, fileName);
end
a = imread('cameraman.tif');
aa=blockproc(a, [257 257], @(bs)cropSaveBlock(bs.data),'BorderSize', [1 1 ])
% aa=blockproc(a, [257 257], @(bs)cropSaveBlock(bs),'BorderSize', [123 123 ])

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by