设计一个程序用matlab的gui将图像放大
时间: 2023-12-01 13:03:57 浏览: 88
以下是一个简单的Matlab GUI程序,可以将输入图像放大。该程序使用了Matlab中的imresize函数来对图像进行缩放。
```matlab
function image_zoom_GUI
% 创建GUI窗口
hfig = figure('Name', 'Image Zoom', ...
'Position', [200 200 400 400], ...
'NumberTitle', 'off');
% 创建按钮
uicontrol(hfig, 'Style', 'pushbutton', ...
'String', 'Open Image', ...
'Position', [20 350 100 30], ...
'Callback', @open_image_callback);
uicontrol(hfig, 'Style', 'pushbutton', ...
'String', 'Zoom In', ...
'Position', [140 350 100 30], ...
'Callback', @zoom_in_callback);
uicontrol(hfig, 'Style', 'pushbutton', ...
'String', 'Zoom Out', ...
'Position', [260 350 100 30], ...
'Callback', @zoom_out_callback);
% 创建显示图像的axes
haxes = axes('Parent', hfig, ...
'Units', 'pixels', ...
'Position', [20 50 360 280]);
% 图像句柄
him = [];
% 打开图像
function open_image_callback(hObject, eventdata)
[filename, pathname] = uigetfile({'*.jpg;*.jpeg;*.png;*.bmp', 'Image Files (*.jpg,*.jpeg,*.png,*.bmp)'});
if isequal(filename,0) || isequal(pathname,0)
return;
end
img = imread(fullfile(pathname, filename));
imshow(img, 'Parent', haxes);
him = findobj(haxes, 'Type', 'image');
end
% 放大图像
function zoom_in_callback(hObject, eventdata)
if isempty(him)
return;
end
img = get(him, 'CData');
img_zoomed = imresize(img, 2);
imshow(img_zoomed, 'Parent', haxes);
end
% 缩小图像
function zoom_out_callback(hObject, eventdata)
if isempty(him)
return;
end
img = get(him, 'CData');
img_zoomed = imresize(img, 0.5);
imshow(img_zoomed, 'Parent', haxes);
end
end
```
该程序包含三个按钮:"Open Image"、"Zoom In" 和 "Zoom Out"。用户可以通过单击 "Open Image" 按钮来选择要打开的图像文件。然后,用户可以使用 "Zoom In" 和 "Zoom Out" 按钮来放大或缩小图像。程序使用imshow函数在GUI窗口中显示图像,并使用imresize函数来对图像进行缩放。
阅读全文
相关推荐
















