How to convert a figure in matrix of pixel?
8 views (last 30 days)
Show older comments
SAC CSA
on 14 Dec 2021
Commented: Walter Roberson
on 17 Dec 2021
I have a picture and I want to convert this into a numeric matrix. I want to create a matrix of 1's and 0's where the 0's represent the orange pixels and the 1's represent the transparent pixels.
Can anybody help me?
4 Comments
Accepted Answer
Walter Roberson
on 14 Dec 2021
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/834235/image.png';
img = imread(filename);
whos
bw = imbinarize( rgb2gray(img) );
whos bw
imshow(bw)
Notice that the result is logical datatype, with 1 for the white pixels and 0 for the black pixels. Depending exactly what you are doing, you might need to convert that to double precision -- for example if you are wanting to use it as Alpha data, you will need to convert to double precision.
4 Comments
Walter Roberson
on 17 Dec 2021
Depth cannot be calculated from a single 2d picture (unless there are cues such as color)
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!