简介:介绍如何使用MATLAB GUI界面实现对图像的各种操作,包括读取、显示、旋转、缩放、裁剪和保存等。
在MATLAB中,我们可以使用图形用户界面(GUI)来创建一个应用程序,该程序允许用户对图像进行各种操作。以下是一个简单的例子,展示如何创建一个GUI界面,实现对图像的读取、显示、旋转、缩放、裁剪和保存等操作。
% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% 读取图像文件img = imread('image.jpg');% 显示图像axes(handles.axes1);imshow(img);% 旋转图像(输入角度值)angle = str2double(get(handles.edit1, 'String'));rotated_img = imrotate(img, angle);imshow(rotated_img);% 缩放图像(输入缩放比例)scale = str2double(get(handles.edit2, 'String'));resized_img = imresize(img, scale);imshow(resized_img);% 裁剪图像(输入裁剪区域坐标)[x, y, w, h] = get_crop_region(handles);cropped_img = imcrop(img, [x y w h]);imshow(cropped_img);% 保存图像(选择保存路径)save_path = uiputfile({'*.jpg';'*.png';'*.*'}, 'Save Image');imwrite(cropped_img, save_path);end