Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How to assign Pixel values to the entire images?

Asked by Mohan Prasath Thirumalaisamy on 16 Jan 2013

Hi, I have set of images and then i need to make those images into 32*32. I did this by using imresize. Now i have 32*32 pixel image, then i need to image pixel value between 0 and 1. I know that i can use rand(32, 32) to have values between 0 and 1. how i can give it to the image?

1 Comment

Jan Simon on 16 Jan 2013

The question is not clear. What does "giving to the image" mean?

Mohan Prasath Thirumalaisamy

Products

No products are associated with this question.

2 Answers

Answer by Matt J on 16 Jan 2013
Accepted answer
 a=min(A(:));
 b=max(A(:));
 B=(A-a)/(b-a);

5 Comments

Jurgen on 16 Jan 2013

if A is uint8 you must do double(A)/255

Even then, dividing by 255 is dangerous as it assumes min(A(:)) = 0, which need not be the case.

Matt J on 16 Jan 2013

It also assumes that max(A(:))=255 which need not be the case. But the kind of normalization asked for here is still not clear (the image could be the first in a series ranging from 0 to 255 for example). So, it could be valid...

hi really thanks for your idea.

Matt J
Answer by Jurgen on 16 Jan 2013

Not 100% sure what format your images are, but try this:

If A is your 32x32 image, then

A = mat2gray(A)

will scale it to 0-1. Alternatively, if you want to keep relative intensities: use

A = im2double(A). 

If your image contains real values in a larger range (that contains the 0-1 subrange), and you only want to show the pixels in that 0-1 range: (and clip others at black or white)

A = mat2gray(A,[0 1])

0 Comments

Jurgen

Contact us