Extract values from a fig file?

3 views (last 30 days)
Hi, I have a file like "Example.fig" that contains a picture
and I want to extract the values of each pixel and put them in a matrix form so I can work with them
What can I do?

Accepted Answer

Star Strider
Star Strider on 8 Jun 2023
Try this —
F = openfig('Example.fig'); % Load File & Display Contents
Ax = gca; % Get Axis Handle
Fmtx = Ax.Children.CData % Get Image Data
Fmtx = 15×15
0.0851 0.0864 0.0822 0.0839 0.0864 0.0862 0.0861 0.0856 0.0849 0.0832 0.0864 0.0823 0.0807 0.0838 0.0772 0.0798 0.0802 0.0836 0.0853 0.0893 0.0905 0.0854 0.0840 0.0849 0.0873 0.0873 0.0827 0.0812 0.0832 0.0807 0.0817 0.0797 0.0840 0.0944 0.1072 0.1059 0.0898 0.0897 0.0885 0.1039 0.1067 0.0885 0.0833 0.0800 0.0836 0.0829 0.0847 0.0847 0.1018 0.1213 0.1168 0.0910 0.0865 0.0894 0.1136 0.1204 0.0982 0.0819 0.0789 0.0803 0.0806 0.0820 0.0830 0.1000 0.1214 0.1198 0.0953 0.0860 0.0931 0.1172 0.1206 0.0995 0.0858 0.0835 0.0790 0.0802 0.0831 0.0833 0.1002 0.1199 0.1165 0.0956 0.0887 0.0947 0.1220 0.1230 0.0983 0.0832 0.0811 0.0801 0.0774 0.0827 0.0854 0.1001 0.1215 0.1168 0.0963 0.0933 0.0989 0.1240 0.1229 0.1021 0.0807 0.0785 0.0804 0.0750 0.0792 0.0802 0.0991 0.1213 0.1218 0.1183 0.1179 0.1190 0.1244 0.1241 0.1115 0.0816 0.0802 0.0801 0.0750 0.0803 0.0815 0.0980 0.1190 0.1192 0.1161 0.1180 0.1216 0.1268 0.1215 0.1138 0.0848 0.0785 0.0777 0.0753 0.0761 0.0797 0.0872 0.0992 0.1037 0.1000 0.0991 0.1024 0.1236 0.1208 0.1072 0.0832 0.0739 0.0741
figure
surf(Fmtx) % Plot Image Data As 'surf'
colormap(turbo)
set(gca, 'YDir','reverse')
view(-30, 60)
title('Recovered Data Matrix')
.

More Answers (1)

Vinayak Agrawal
Vinayak Agrawal on 9 Jun 2023
Hi MementoMori,
According to me these commands will help you get the results
>>s=load('Example.fig','-mat'); %opening the figure
>> values=s.hgS_070000.children(1).children.properties.CData; %storing pixel values
>> fig = imagesc(values); %verifying by plotting the ‘values’ which are our pixel values
You can see the pixel values by double clicking on ‘values’ variable created in your workspace
You can refer to these documents also-
Hope it helps!

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!