How to convert a figure in matrix of pixel?

11 views (last 30 days)
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
SAC CSA
SAC CSA on 14 Dec 2021
@Rik and @Benjamin. The Mathematica code for this procedure is relatively simple, but I would like to get a version of the code in matlab.
image = Import["https://i.stack.imgur.com/CQkvZ.png"]
data = ImageData[ChanVeseBinarize[image]]

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Dec 2021
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/834235/image.png';
img = imread(filename);
whos
Name Size Bytes Class Attributes filename 1x79 158 char img 373x363x3 406197 uint8
bw = imbinarize( rgb2gray(img) );
whos bw
Name Size Bytes Class Attributes bw 373x363 135399 logical
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
Walter Roberson on 17 Dec 2021
Depth cannot be calculated from a single 2d picture (unless there are cues such as color)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!