Image processing with sub images

조회 수: 2 (최근 30일)
Aravind Prabhu Gopala Krishnan
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
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?
Aravind Prabhu Gopala Krishnan
Aravind Prabhu Gopala Krishnan 2021년 8월 12일
Sorry i forgot to comments those variables.... Exactly wat i need is, this code having window size of 25 as you see the variable SZ. Using these for loop i divide the Image (I) into subimages(blocks) which giving me cells of 232^2 = appr.53800 subimages. I dont need that much subimages. So i want to move this sliding window with stride value 3. Now this code moving that sliding window of stride value=1 i.e 1pixel right and 1 pixel down. Instead of that i need to move 3 pixel right and 3 pixel down. By doing this i can reduce my subimages. Main thing is i cannot use inbuild function and montage is just to view the image.
clc;
clear all;
SZ = 25;
M = 232;
N=232;
% 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])

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

채택된 답변

DGM
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
  댓글 수: 1
Aravind Prabhu Gopala Krishnan
Aravind Prabhu Gopala Krishnan 2021년 8월 12일
Thank you very much bro.....this is wat i exactly needed.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by