Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Reference to non-existent field 'Image'
Replies: 2   Last Post: Jul 30, 2012 11:02 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Julian

Posts: 93
Registered: 12/6/04
Reference to non-existent field 'Image'
Posted: Jul 30, 2012 5:21 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hey guys,

So Iv written a GUI image analyzer that, at least a few years ago, was working fine. I have recently opened it up again, and its been presenting me with some problems. The GUI in question contains 3 axes figures, each of which will have something different plotted or displayed within it.

My first error occurs when I attempt to load an image. The axes I am attempting to display the image in is tagged as Image in GUIDE. I have repeatedly checked this to be true. When I attempt to load it, I am returned the error: Reference to non-existent field 'Image'. (this is in reference to line 122, which I have highlighted in my code below)

However, when I tried commenting out that line of code, the image was loaded into the first axes just fine. But this doesnt help me when I need to load data into the other 2 axes.

Then adjusting the contrast is giving me issues too. It seems as if practically nothing is working in my GUI any more, but I don't know why. I got an A on this project, so I know it worked at some point.

Below is a copy of my code. What I am most concerned with is figuring out how to get MATLAB to recognize the the handles I have assigned to the objects in my GUI, which it is apparently not doing. Any additional help that could be provided would be greatly appreciated. Thanks in advance!

%**************************************************************************
% This GUI is used to the purposes of analyzing images and obtaining data
% about them. These data are the area and intensity of objects within the
% image. This analyzer also allows the user to adjust the contrast of an
% image, convert the image to black and white, adjust the threshold used
% for the black and white conversion, select a specific region of the image
% to study, and plot the area and intensity data against eachother. The
% selected region and the area/intensity data can also be saved in this GUI
%**************************************************************************

function varargout = cellGUI(varargin)
% CELLGUI M-file for cellGUI.fig
% CELLGUI, by itself, creates a new CELLGUI or raises the existing
% singleton*.
%
% H = CELLGUI returns the handle to a new CELLGUI or the handle to
% the existing singleton*.
%
% CELLGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CELLGUI.M with the given input arguments.
%
% CELLGUI('Property','Value',...) creates a new CELLGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before cellGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to cellGUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help cellGUI

% Last Modified by GUIDE v2.5 30-Jul-2012 17:02:55

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @cellGUI_OpeningFcn, ...
'gui_OutputFcn', @cellGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before cellGUI is made visible.
function cellGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to cellGUI (see VARARGIN)

% Choose default command line output for cellGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes cellGUI wait for user response (see UIRESUME)
% uiwait(handles.ImageAnalyzer);


% --- Outputs from this function are returned to the command line.
function varargout = cellGUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


function InputLoad_Callback(hObject, eventdata, handles)
% hObject handle to InputLoad (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of InputLoad as text
% str2double(get(hObject,'String')) returns contents of InputLoad as a double

FileName = get(hObject, 'String'); % Returns the contents of the input box as a string and...
% assigns that string to the variable "FileName"

handles.FileName = FileName; % Assigns the variable "FileName" a handle
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function InputLoad_CreateFcn(hObject, eventdata, handles)
% hObject handle to InputLoad (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in LoadButton.
function LoadButton_Callback(hObject, eventdata, handles)
% hObject handle to LoadButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

image = imread(handles.FileName); % Loads the image data assigned to "handles.FileName" and assigns that data to the variable "image"
image2 = im2double(image); % Converts the image data in "image" to type double and saves that data to the variable "image2"
LINE 122 --> axes(handles.Image); % Specifies the axes window that the image should be displayed in
imshow(image2) % Displays the image
old_min = min(min(image2)); % Finds the minimum intensity value of the image
old_max = max(max(image2)); % Finds the maximum intensity value of the image
handles.old_min = old_min; % Assigns the minimum intensity value to a handle
handles.old_max = old_max; % Assigns the maximum intensity value to a handle
handles.image2 = image2; % Assigns the image (now in type double form) to a handle
guidata(hObject, handles);


% --- Executes on slider movement.
function ThresholdAdjust_Callback(hObject, eventdata, handles)
% hObject handle to ThresholdAdjust (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider

Threshold = get(hObject, 'Value'); % Assigns the value that corresponds to the position...
% of the slider to the variable "Threshold"

i2mod = handles.i2mod; % Calls the variable that corresponds to the handle "handles.i2mod"...
% so that it may be used in this function (see line 288)

ibw = im2bw(i2mod, Threshold); % Converts the image "i2mod" to a black and white image based...
% on the input (via slider) for "Threshold"

axes(handles.ThresholdPlot); % Specifies the axes window that the black and white image should be displayed in
se = strel('disk',2); % Scans the image with a disk shape to create a morphological structuring element
ibw2 = imopen(ibw,se); % Noise removal; erodes then dilates image
imshow(ibw2) % Displays noise removed image
handles.ibw2 = ibw2; % Assigns the variable "ibw2" to a handle
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function ThresholdAdjust_CreateFcn(hObject, eventdata, handles)
% hObject handle to ThresholdAdjust (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end


function InputSaveData_Callback(hObject, eventdata, handles)
% hObject handle to InputSaveData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of InputSaveData as text
% str2double(get(hObject,'String')) returns contents of InputSaveData as a double

SDFileName = get(hObject, 'String'); % Returns the contents of the input box as a string and ...
% assigns that string to the variable "SDFileName"

handles.SDFileName = SDFileName; % Assigns the variable "SDFileName" to a handle
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function InputSaveData_CreateFcn(hObject, eventdata, handles)
% hObject handle to InputSaveData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in SaveData.
function SaveData_Callback(hObject, eventdata, handles)
% hObject handle to SaveData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

area = handles.area; % Calls the variable that corresponds to the handle "handles.area"...
% so that it may be used in this function (see line 348)

I = handles.intensity; % Calls the variable that corresponds to the handle "handles.intensity"...
% so that it may be used in this function (see line 359)

intensity = I; % Reassigns the variable "I" to the variable "intensity" (so that when the data is called...
% after it has been saved, "I" will be shown as "intensity rather than "I")

SDFileName = handles.SDFileName; % Calls the variable that corresponds to the handle "handles.SDFileName"...
% so that it may be used in this function (see line 181)

save(handles.SDFileName, 'area', 'intensity'); % Saves the area and intensity data to the file name as specified by handles.SDFileName
guidata(hObject, handles);


% --- Executes on button press in exit.
function exit_Callback(hObject, eventdata, handles)
% hObject handle to exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

close(handles.ImageAnalyzer); % Closes the image analyzer GUI


function NMin_Callback(hObject, eventdata, handles)
% hObject handle to NMin (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of NMin as text
% str2double(get(hObject,'String')) returns contents of NMin as a double

new_min = str2num(get(hObject, 'String')); % Converts the input numbers in the "New Minimum Intensity"...
% edit box from a character array to a numeric matrix for calculation...
% then assignes that matrix to the variable "new_min"

handles.new_min = new_min; % Assigns the variable "new_min" to a handle
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function NMin_CreateFcn(hObject, eventdata, handles)
% hObject handle to NMin (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in SubmitIntensity.
function SubmitIntensity_Callback(hObject, eventdata, handles)
% hObject handle to SubmitIntensity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

old_min = handles.old_min; % Calls the variable that corresponds to the handle "handles.old_min"...
% so that it may be used in this function (see line 126)

old_max = handles.old_max; % Calls the variable that corresponds to the handle "handles.old_max"...
% so that it may be used in this function (see line 127)

new_min = handles.new_min; % Calls the variable that corresponds to the handle "handles.new_min"...
% so that it may be used in this function (see line 241)

new_max = handles.new_max; % Calls the variable that corresponds to the handle "handles.new_max"...
% so that it may be used in this function (see line 303)

image2 = handles.image2; % Calls the variable that corresponds to the handle "handles.old_min"...
% so that it may be used in this function (see line 128)

i2mod = imadjust(image2, [old_min old_max], [new_min new_max]); % Adjusts the contrast of "image2" by moving the pixel intensity...
% range from the origonal range as bounded by "old_min" and "old_max"...
% to a new range as bounded by "new_min" and "new_max" and assignes...
% this new image to the variable "i2mod"

axes(handles.Image); % Specifies which axes window to display the contrast adjusted image in...
% (this is the same window the origonal image was displayed in)

imshow(i2mod) % Displays contrast adjusted image
handles.i2mod = i2mod; % Assigns the variable "i2mod" to a handle
guidata(hObject, handles);


function NMax_Callback(hObject, eventdata, handles)
% hObject handle to NMax (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of NMax as text
% str2double(get(hObject,'String')) returns contents of NMax as a double

new_max = str2num(get(hObject, 'String')); % Converts the input numbers in the "New Maximum Intensity" edit box from a character...
% array to a numeric matrix for calculation, then assignes that matrix to the variable "new_max"

handles.new_max = new_max; % Assigns the variable "new_max" to a handle
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function NMax_CreateFcn(hObject, eventdata, handles)
% hObject handle to NMax (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in crop.
function crop_Callback(hObject, eventdata, handles)
% hObject handle to crop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

i2mod = handles.i2mod; % Calls the variable that corresponds to the handle "handles.i2mod"...
% so that it may be used in this function (see line 288)

ibw2 = handles.ibw2; % Calls the variable that corresponds to the handle "handles.ibw2"...
% so that it may be used in this function (see line 154)

axes(handles.ThresholdPlot); % Specifies which axes window to display the threshold adjusted image in
ibwInterest = roipoly(ibw2); % Allows a region of interest to be selected and assigns that region to the variable "ibwInterest"

ibwInterest = immultiply(ibwInterest,ibw2); % Multiplies "ibwInterest" with "ibw2" and then reassignes...
% the variable "ibwInterest" to this new value

[L,num] = bwlabeln(ibwInterest); % Labels connected components of ibwInterest and returns...
% a label matrix "L" containing the labels for the connected...
% components of ibwInterest and returns "num", which is the...
% number of connected objects found in ibwInterest

handles.ibwInterest = ibwInterest; % Assigns the variable "ibwInterest" to a handle
info = regionprops(L,'Area'); % Finds the area of every labeled region in "L" and saves...
% those data in the structure array "info" under the sub-element "Area"

area = [info.Area]; % Assigns the data saved in "info.Area" to the variable "area"
handles.area = area; % Assigns the variable "area" to a handle

% This loop finds the absolute maximum intensity of each labeled region within the selected region of the image
for i = 1:num % Assigns the variable "i" to an array consisting of numbers ranging from 1 to the number of contected objects in ibwInterest
A = L == i; % Assigns the variable "A" to the data that corresponds to where ever "L" (the label matrix) is equal to "i"
i4 = immultiply(A, i2mod); % Multiplies "A" with "i2mod" to produce a selected region with the...
% intensity of the origonal image (before black and white conversion)...
% and then assigns these data to the variable "i4"

I(i) = max(max(i4)); % Finds the absolute maximum value in "i4" and then assigns that value to every value of "i" within "I"
end
handles.intensity = I; % Assigns the variable "I" to a handle
axes(handles.ScatterPlot); % Specifies which axes window to display the scatter plot in
scatter(I, area); % Creates a scatter plot of "I" vs "area"
guidata(hObject, handles);


function InputSaveRegion_Callback(hObject, eventdata, handles)
% hObject handle to InputSaveRegion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of InputSaveRegion as text
% str2double(get(hObject,'String')) returns contents of InputSaveRegion as a double

SRFileName = get(hObject, 'String'); % Returns the contents of the input box as a string and...
% assigns that string to the variable "SDFileName"

handles.SRFileName = SRFileName; % Assigns the variable "SRFileName" to a handle
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function InputSaveRegion_CreateFcn(hObject, eventdata, handles)
% hObject handle to InputSaveRegion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in SaveRegion.
function SaveRegion_Callback(hObject, eventdata, handles)
% hObject handle to SaveRegion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

ibwInterest = handles.ibwInterest; % Calls the variable that corresponds to the handle "handles.ibwInterst"...
% so that it may be used in this function (see line 343)

SRFileName = handles.SRFileName; % Calls the variable that corresponds to the handle "handles.SRFileName"...
% so that it may be used in this function (see line 376)

imwrite(ibwInterest, handles.SRFileName); % Saves the image "ibwInterest" to the file name as specified by handles.SRFileName
guidata(hObject, handles);



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.