Image processing with sub images
조회 수: 3 (최근 30일)
이전 댓글 표시
Aravind Prabhu Gopala Krishnan
2021년 8월 12일
댓글: Aravind Prabhu Gopala Krishnan
2021년 8월 12일
Hello everyone here is my code which is breaking image of size 256x256 into subimages of 232^2 = 53800 subimage. But I need to adjust stride values and have to decrease the subimages to the range of 200 to 500 subimages. Here Stride is acting as 1 but i cannot adjust stride here. I cant use mat2cell or mat2tile in this project.
clc;
clear all;
SZ = 25;
M = 232;
N=232;
stepX = 3;
stepY = 3;
index_x = 0;
index_y = 0;
i = 0;
j = 0;
% blocks = cell(N,M);
img = imread('C:\Users\91894\Desktop\matlab\PNEUMONIA\person1_bacteria_1.jpeg');
img1 = imresize(img,[256 256]);
I = rgb2gray(img1);
blocks = cell(N,M);
for idx = 1 : N
for idy = 1:M
blocks{idx,idy} = I(idx:idx+SZ-1, idy:idy+SZ-1 , :);
end
end
montage(blocks.','Size',size(blocks),'BorderSize',[5,5])
댓글 수: 4
DGM
2021년 8월 12일
I don't know what exactly you're trying to do. I see a bunch of unused variables and then you make a padded montage of blocks. What part of the example doesn't suit what you want? Are you just trying to avoid using montage()? If so, why not just build the output directly in the loop?
채택된 답변
DGM
2021년 8월 12일
I don't know if this is what you're after
I = imread('cameraman.tif');
SZ = 25;
stepsize = 3;
M = floor((size(I,1)-SZ+1)/stepsize);
N = floor((size(I,2)-SZ+1)/stepsize);
blocks = cell(N,M);
for idx = 1:N
for idy = 1:M
bx = 1+(idx-1)*stepsize;
by = 1+(idy-1)*stepsize;
blocks{idx,idy} = I(bx:bx+SZ-1, by:by+SZ-1 , :);
end
end
by:by+SZ-1 % note that the image isn't integer-divisible with this step size
추가 답변 (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!