How to using my own code to resize image
Mostra commenti meno recenti
teacher assigned a home work to resize the image by computing the average of 4 neighbouring pixels to get one pixel. following are my code, but it is wrong,and I cant figure out why.Here are images before and after reszing, the size changed as well as color imageshack.us/img834/2379/tb7w.jpg I prefer to point out my mistake directly, rather than give me a new code. And I have another question, sometimes my matrix of image is in double type, and it's works, but sometimes it's not, and I need to change it to uint8 type, am I correct? Thanks
a=imread('c:\black and white.jpg');
[rows,columns,layers]=size(a);
i=1;j=1;k=1;
c=zeros(rows/2,columns/2,layers);
c=uint8(c);
for x=1:2:rows-1;
for y=1:2:columns-1;
for z=1:layers;
c(i,j,k)=1/4*(a(x,y,z)+a(x,y+1,z)+a(x+1,y,z)+a(x+1,y+1,z));
k=k+1;
end
j=j+1;
k=1;
end
i=i+1;
j=1;
k=1;
end
figure, imshow(a)
figure, imshow(c)
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Image Processing Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!