How can I downsample an image?

Hello
I want to downsample an image and I want to replace one pixel in new Image with average of four pixel in first image.
Could you help me ?

 Risposta accettata

Letting the image be IM and assuming it is double(),
NewImage = (IM(1:2:end, 1:2:end) + IM(2:2:end, 1:2:end) + IM(1:2:end, 2:2:end) + IM(2:2:end, 2:2:end)) / 4;

3 Commenti

bkshn
bkshn il 4 Lug 2015
Hello walter Roberson, thanks for your answer.
I have a question Does this formula contains all pixels in an Image?
Could you help me How it works?
This formula processes all pixels in the image at the same time. I just noticed that it will fail if the height or width are odd.
It works by taking the average of the pixels at (I,J), (I+1,J), (I,J+1), (I+1,J+1), doing so for every second row and ever second column.
bkshn
bkshn il 8 Lug 2015
Hello Walter Roberson
I think it's ok for grayscale image. Could you help me about rgbImage?
thanks

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Read, Write, and Modify Image 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!

Translated by