Hi, I want a 2d array of rows and columns filled with floating point numbers (matrix) which can be converted to a grayscale image.
1 view (last 30 days)
Show older comments
Should i use the mat2gray function of matlab ? I want to program my own image and fill it with numbers.
4 Comments
Walter Roberson
on 25 Feb 2016
repmat(A,B,C) makes B vertical copies and C horizontal copies. When A is a row vector that means you would end up with B rows.
Answers (1)
Cam Salzberger
on 29 Feb 2016
Hello Anvinder,
I understand that you are looking to display a grayscale image based on values from a matrix. As jgg said, "mat2gray" helps in ensuring that the matrix values get scaled appropriately (between 0 and 1) to display the full range in an image.
You don't need to use "repmat" to create the grayscale image, that was just an example. Here's an example that uses loops to allow for calculating each pixel value:
nRows = 10;
nCols = 15;
A = zeros(nRows,nCols);
for r = 1:nRows
for c = 1:nCols
A(r,c) = r+c/2;
end
end
I = mat2gray(A);
imshow(I)
I hope this helps!
-Cam
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!