Image processing with sub images

3 visualizaciones (últimos 30 días)
Aravind Prabhu Gopala Krishnan
Aravind Prabhu Gopala Krishnan el 12 de Ag. de 2021
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 comentarios
DGM
DGM el 12 de Ag. de 2021
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 el 12 de Ag. de 2021
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])

Iniciar sesión para comentar.

Respuesta aceptada

DGM
DGM el 12 de Ag. de 2021
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 comentario
Aravind Prabhu Gopala Krishnan
Aravind Prabhu Gopala Krishnan el 12 de Ag. de 2021
Thank you very much bro.....this is wat i exactly needed.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by