creating a frame(image), randn

4 views (last 30 days)
PChoppala
PChoppala on 13 Oct 2011
Hello,
Appreciate some quick help from you, my dear Matlab friends!
a = randn(20,20) + sqrt(3)*randn
imshow(a)
will create an image with 20x20 pixels, each pixel with the size 1x1. the values in the pixels are pseudo random number which are Gaussian with variance '3'.
Can i say that the pixel intensity of this image is shown in gray linear scale, assuming the value of the pixel is the pixel intensity?

Accepted Answer

David Young
David Young on 13 Oct 2011
Your existing code will clip the pixel values at 0 and 1, so all the negative values are shown as black and all values greater than 1 as white. The intensity scale is therefore very much not linear.
Instead of imshow(a), use
imshow(a, []);
The pixel values will then be mapped to intensities approximately linearly (but only approximately, because it depends on the physical response of your screen and its associated electronics). The value nearest to -infinity will be displayed as black, and the value nearest to +infinity as white, with the other values distributed through the gray shades between.
You can also specify the mapping imshow uses with imshow(a, [blackval whiteval]) - see the documentation.
By the way, I don't think randn(20,20) + sqrt(3)*randn produces the distribution you describe. Do you perhaps mean sqrt(3)*randn(20,20)?
  2 Comments
PChoppala
PChoppala on 13 Oct 2011
Thanks about imshow(a, ([]))
I need to create a frame with 20x20 pixels, size of each pixel to be 1x1 and a standard deviation of sigma = 3. Its Gaussian in nature. So I thought,
a = randn(20,20) + sqrt(3)*randn
imshow(a, ([]))
would work!
Is that wrong?
Is, a = sqrt(3) * randn(20,20) correct?
Image Analyst
Image Analyst on 13 Oct 2011
The second one is correct, for a mean of zero. Add the desired mean to shift it so that it has the desired mean. See the example in the help.

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!