Determine average of an image in .fig format

2 views (last 30 days)
Hi all,
I've saved a number of images as .fig as a result of extensive computations in Matlab 2007b. However, I would like to glean some extra info from these images without having to reprocess all files. I simply want to get the mean of a number of values dictated by a defined region (set by rect()). Is this possible? Obviously my matrices of values are no longer in memory, in which case this would be easy. I've been using uiopen to view the files; is there another option that would allow me to perform this?
Any advice would be appreciated, Kista

Accepted Answer

Susan
Susan on 11 Feb 2013
Edited: Susan on 11 Feb 2013
Hi,
Thanks for your comment.
I just learned that a .fig file is simply a .mat file with a different extension, so if you don't want to actually render the image you can do
>> s = load('filename.fig','-mat');
to load the data as a structure into the workspace and yield the variable values in the 'children' field of the structure. Doing this has saved me a lot of processing and heartache. Please find a basic version of mine below for reference.
Kind regards, Kista Susan
% Code to yield the mean of a user defined region in a saved .fig plot
clear; clc;
uiopen('file.fig',1);
h = imrect(gca,[]); % draw region of interest
api = iptgetapi(h);
position2 = (api.getPosition());
position = uint32(position2);
s = load('file.fig','-mat');
% Output mean index value for this region; note: I used an original subplot so my data of interest was in children(3,1).
format short;
mean_v = mean2(s.hgS_070000.children(3,1).children(1,1).properties.CData(position(2):position(2)+position(4),position(1):position(1)+position(3)));
close all;

More Answers (3)

Shashank Prasanna
Shashank Prasanna on 8 Feb 2013
Edited: Shashank Prasanna on 8 Feb 2013
Here is an example you can hopefully modify it for your use:
% Create a figure with a rectangle:
rectangle('Position',[0.59,0.35,3.75,1.37],'LineWidth',2,'LineStyle','--')
hgsave(gcf,'rect.fig'); % you can save it manually from file if you like.
h = importdata('rect.fig');
pos = h.children.children.properties.Position
pos =
0.5900 0.3500 3.7500 1.3700
How did i find the position properties, well you can just explore the entire 'h' structure, depending on what type of image you have you can extract the properties appropriately. You can later maybe do a sum average etc.

Image Analyst
Image Analyst on 8 Feb 2013
Just avoid the problem in the first place. Don't save images as .fig files. Save them as image files, for example .PNG files. Then you simply read it back in with imread() and get the mean with mean2():
grayImage = imread(fullFileName);
theMean = mean2(grayImage(row1:row2, col1:col2));

Susan
Susan on 11 Feb 2013
Hi all,
Thanks for your replies. However, I should clarify a bit.
The computation I performed to yield my figures had a colorbar scaled to min and max velcoity values based on my computations. I do not simply want the grayscale value, I want the specific mean velocity value obtained by my processing over a set region. If I open a .fig and use the data cursor I can see the index values relating to velocity at each location. Obviously I don't have the resulting matrices still in memory to compute the mean2 as I would normally. Is there a way to compute this mean just from the plot alone? I've been playing around with imrect but I need some advice on whether this is possible without me going back and reprocessing all data again.
Kind regards, Kista
  1 Comment
Image Analyst
Image Analyst on 11 Feb 2013
Saving as a fig file is a mistake. Save the variables in a mat file and you'll be able to get the numbers out exactly as they were.

Sign in to comment.

Categories

Find more on Images 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!