Error while evaluating UIControl Callback.

Hi Professors and Fellow users of MATLAB, I recently started using MATLAB ( for this subject) . I am having this error while executing the GUI file. Can someone please help me in solving this error.
Thankyou.
Best Regards.
Code:
% UIWAIT makes CourseworkGui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = CourseworkGui_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;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile('*.*'); % Open a file browser
if filename == 0 % If the user didn't choose an image
disp("Please, select an image.");
else
handles.image_name = filename; % Put the file name to handles
handles.image_path = pathname; % Put the file path to handles
handles.image = imread(handles.image_name); % Read the image
imshow(handles.image, 'parent', handles.axes1) % Display the image on the axes1
guidata(hObject, handles); % Save the handles info.
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
tempImg = handles.image;
[x, y, z] = size(tempImg); % Get a dimension of the image.
% If the image is colour, the image will be converted to grayscale image
if z == 3
handles.image = rgb2gray(tempImg); % RGB colour to grayscale
guidata(hObject, handles); % Save the handles info.
end
imshow(handles.image, 'parent', handles.axes1) % Display the image on the axes1
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
val = get(hObject, 'Value'); % Get the selected value on the pop up menu
handles.dctType = val; % Set the forward-DCT type
guidata(hObject, handles); % Save the handles info.
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% Hint: popupmenu 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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% Jpeg Compresstion [flattened Image] = JpegCompression(ImageName, Compresstion rate, DCT type, I-DCT type)
newImg = py.myJpeg.JpegCompression(handles.image_name, handles.compression_rate, handles.dctType, handles.idctType);
% reshape the flattened image to 2D or 3D image
[x, y, z] = size(handles.image); % Get a dimension of the image.
newImg = reshape(cellfun(@uint8, cell(newImg)), x, y, z);
imshow(newImg, 'parent', handles.axes2) % Display the image on the axes2
handles.newImage = newImg; % Put the JPEG image to handles
% Display count to know the process finished
handles.count = handles.count + 1;
str = sprintf("Test-%d", handles.count);
set(handles.edit3, 'String', str);
guidata(hObject, handles); % Save the handles info.
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
image = handles.newImage;
if image == 0 % If there is no JPEG image data
disp("There is no image data.");
else
% Open the browser to get the file name and the path the user selected
[filename, pathname] = uiputfile('.jpeg');
% Check the file name whether the user puts the file name or not
if filename ~= 0
filepath = strcat(pathname, filename); % Make whole file path with the file name
imwrite(image, filepath); % Save the image
end
end
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
handles.axes1 = gca; % Get the handle of axes1
set(handles.axes1, 'XColor','none','YColor','none'); % Set the axes1 properties
guidata(hObject, handles); % Save the handles info.
% --- Executes during object creation, after setting all properties.
function axes2_CreateFcn(hObject, eventdata, handles)
handles.axes2 = gca; % Get the handle of axes2
set(handles.axes2, 'XColor','none','YColor','none'); % Set the axes2 properties
guidata(hObject, handles); % Save the handles info.
function edit1_Callback(hObject, eventdata, handles)
filename = get(hObject, 'String'); % Get the selected value on the pop up menu
handles.newImage_name = filename; % Set the new image name
guidata(hObject, handles); % Save the handles info.
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
image = handles.newImage;
imagepath = handles.image_path;
imagename = handles.newImage_name;
imageformat = handles.newImage_format;
if image == 0 % Check the image array
disp("There is no image data.");
else
if isempty(imagename) == 1 % Check if the user put the file name or not
disp("Please, enter the file name.")
else
% Make file name with the JPEG compression information
% (image path + image name + compression rate + DCT type + IDCT type + file format)
filename = sprintf('%s%s_K%.0f_D%d_ID%d.%s', imagepath, imagename, handles.compression_rate, handles.dctType, handles.idctType, imageformat);
imwrite(image, filename);
end
end
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% User selected JPG image format
if (get(handles.radiobutton1, 'Value')) % Get the radio button handle and set the others off
set(handles.radiobutton2, 'Value', 0)
set(handles.radiobutton3, 'Value', 0)
handles.newImage_format = "jpg"; % Set the image format JPG
guidata(hObject, handles); % Save the handles info.
end
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% User selected BMP image format
if (get(handles.radiobutton2, 'Value')) % Get the radio button handle and set the others off
set(handles.radiobutton1, 'Value', 0)
set(handles.radiobutton3, 'Value', 0)
handles.newImage_format = "bmp"; % Set the image format BMP
guidata(hObject, handles); % Save the handles info.
end
% Hint: get(hObject,'Value') returns toggle state of radiobutton2
% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% User selected JPEG image format
if (get(handles.radiobutton3, 'Value')) % Get the radio button handle and set the others off
set(handles.radiobutton1, 'Value', 0)
set(handles.radiobutton2, 'Value', 0)
handles.newImage_format = "jpeg"; % Set the image format JPEG
guidata(hObject, handles); % Save the handles info.
end
% Hint: get(hObject,'Value') returns toggle state of radiobutton3
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
figure('Name','Quantization Table','NumberTitle','off')
image(handles.quantization_table);
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
val = get(hObject, 'Value'); % Get the selected value on the pop up menu
handles.compression_rate = val; % Set the compression rate
set(handles.edit2, 'String', sprintf('%.2f', val)); % Display compression rate on the edit box
guidata(hObject, handles); % Save the handles info.
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (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 edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
str = get(handles.edit2, 'String'); % Get the compression rate
val = str2double(str); % Convert the string type to double type
if val >= 0.0 && val <= 100.0 % Check if the compression rate exceed the limit or not
handles.compresstion_rate = val; % Set the compression rate
guidata(hObject, handles); % Save the handles info.
set(handles.slider1, 'Value', val); % Move the slider bar on proper position
else
disp("Error : invalid value.");
end
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
val = get(hObject, 'Value'); % Get the selected value on the pop up menu
handles.idctType = val; % Set the inverse-DCT type
guidata(hObject, handles); % Save the handles info.
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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
Error:
Unable to resolve the name py.myJpeg.JpegCompression.
Error in CourseworkGui>pushbutton3_Callback (line 144)
newImg = py.myJpeg.JpegCompression(handles.image_name, handles.compression_rate, handles.dctType,
handles.idctType);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in CourseworkGui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)CourseworkGui('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.

1 Comment

From my understanding, you are facing error because of the py.myJpeg.JpegCompression function. Could you provide more information about the compression function so that I can replicate the issue.

Sign in to comment.

Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2021a

Asked:

on 21 Aug 2021

Edited:

on 2 Sep 2021

Community Treasure Hunt

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

Start Hunting!