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

5 vues (au cours des 30 derniers jours)
mehmet irfan gedik
mehmet irfan gedik le 28 Déc 2017
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

Réponse acceptée

KSSV
KSSV le 28 Déc 2017
  3 commentaires
Image Analyst
Image Analyst le 28 Déc 2017
See my attached blockproc() demos.
mehmet irfan gedik
mehmet irfan gedik le 29 Déc 2017
thanks but I think so, exactly I could not find the information I wanted , can you help me a little more?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by