How can we split a image into blocks by assigning a block variable ?

2 visualizaciones (últimos 30 días)
how can I split an image into pieces of the dimension I want in Matlab and how do I find the average and standard deviation of each? For this I have to enter a block variable from the keyboard, for instance 2, 3 ,4 etc. and the image will be split into 2x2, 3x3, 4x4 blocks. Thank you for your help
For instance ; I can split image the image with the following code , First, I resize the image I used to 1024x1024 size and then divide it into 512x512 size 4 blocks and then I find the histogram of each one
clc
close all
dosya = fullfile(matlabroot, 'C:\Users\mirfa.IRFAN\Desktop\Sunum\');
alt_dosya = 'image.jpg';
TumDosya = fullfile(dosya, alt_dosya);
if ~exist(TumDosya, 'file')
TumDosya = alt_dosya;
else
HataMesaj = sprintf('Hata: %s bulunamadi.', TumDosya);
uiwait(warndlg(errorMessage));
return;
end
Image = imread(TumDosya);
if(size(Image,3)>1)
GriImage=uint8(zeros(size(Image,1),size(Image,2)));
for i= 1:size(Image,1)
for j=1:size(Image,2)
GriImage(i,j)=0.2989*Image(i,j,1)+0.5870...
*Image(i,j,2)+0.1140*Image(i,j,3);
end % R=0.2989 ; G=0.5870 ; B=0.1140 ;
end
else
GriImage=Image;
end
GriImage=imresize(GriImage,[1024 1024]);
figure; imshow(GriImage); title('Yeniden ölçekleme');
[satir, sutun, numberOfColorChannels] = size(GriImage);
sat2 = floor(satir/2);
sut2 = floor(sutun/2);
blok1 = GriImage(1:(sat2), 1:(sut2), :);
blok2 = GriImage((sat2)+1:end, 1:(sut2), :);
blok3 = GriImage(1:(sat2), (sut2)+1:end, :);
blok4 = GriImage((sat2)+1:end, (sut2)+1:end, :);
figure, imshow(blok1); title('Blok-1');
figure, imshow(blok2); title('Blok-2');
figure, imshow(blok3); title('Blok-3');
figure, imshow(blok4); title('Blok-4');
kendimhist(blok1); title('blok1 histogram');
kendimhist(blok2); title('blok2 histogram');
kendimhist(blok3); title('blok3 histogram');
kendimhist(blok4); title('blok4 histogram');
% imhist(blok1);imhist(blok2);imhist(blok3);imhist(blok4);
% [pixelCounts, grayLevels] = imhist(blok1);
% minGrayLevel = min(blok1(:));
% maxGrayLevel = max(blok1(:));
and the histogram function used in instead of the matlab imhist() function
function[]=kendimhist(img)
% figure,imshow(img);
% title('Orjinal Resim');
matris=zeros(256,1);
x=(0:1:255);
for i=1:size(img,1)
for j=1:size(img,2)
deger=img(i,j);
matris(deger+1)=matris(deger+1)+1;
end
end
figure ;
bar(x,matris);
axis([0 256 0 45000]);
end

Respuesta aceptada

KSSV
KSSV el 28 de Dic. de 2017
  3 comentarios
mehmet irfan gedik
mehmet irfan gedik el 29 de Dic. de 2017
thanks but I think so, exactly I could not find the information I wanted , can you help me a little more?

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by