📄 zoom.m
字号:
%This function is used to room or shrinking an image.
%Function name is imzs.
% -------------------------------------------------------------------
%creat GUI by promgramming,including pushbuttons for zooming/shrinking
%and getting img-path ,edit text for getting the value of v and h of the
%new img.
function imzs
fh = figure('Position',[100 100 512 512]);
start = uicontrol(fh,'Style','pushbutton','String','START',...
'Position',[120 15 80 45],...
'Callback',@zoom_callback);
eth = uicontrol(fh,'Style','edit',...
'String','enter h value',...
'Position',[30 40 80 20],...
'Callback',@edittext_callback);
eth1 = uicontrol(fh,'Style','edit',...
'String','enter v value',...
'Position',[30 15 80 20],...
'Callback',@edit1text_callback);
impath = uicontrol(fh,'Style','pushbutton','String','GET IMG',...
'Position',[220 15 80 45],...
'Callback',@get_img_callback);
% ----------------------------------------------------
% Reseize the img and show it
function zoom_callback(hObject,eventdata)
global h v imgpath;
sprintf('You moved the slider %d units.',h);
f = imread(imgpath);
%fnew = imresize(f,[v h],'bilinear');
[nrows,ncols] = size(f);
%resize the img.
width = v;
height = h;
fnew = uint8(zeros(width,height));
widthScale = nrows/width;
heightScale = ncols/height;
for x = 5:width - 5
for y = 5:height - 5
xx = x * widthScale;
yy = y * heightScale;
if (xx/double(uint16(xx)) == 1.0) & (yy/double(uint16(yy)) == 1.0)
fnew(x,y) = f(int16(xx),int16(yy));
else
a = double(uint16(xx));
b = double(uint16(yy));
x11 = double(I(a,b)); % x11 <- I(a,b)
x12 = double(I(a,b+1)); % x12 <- I(a,b+1)
x21 = double(I(a+1,b)); % x21 <- I(a+1,b)
x22 = double(I(a+1,b+1)); % x22 <- I(a+1,b+1)
fnew(x,y) = uint8( (b+1-yy) * ((xx-a)*x21 + (a+1-xx)*x11) + (yy-b) * ((xx-a)*x22 +(a+1-xx) * x12) );
end
end
end
figure, imshow(fnew),
imwrite(fnew,'new.jpg');
end
% ----------------------------------------------------
% Get the path of the img.
function get_img_callback(hObject,eventdata)
global imgpath
[FileName,PathName] = uigetfile(' ','Select the image');
imgpath = strcat(PathName,'\');
imgpath = strcat(imgpath , FileName);
imshow(imgpath)
end
% ----------------------------------------------------
% Set the value of the edit text component String
function edittext_callback(hObject,eventdata)
global v;
v = str2double(get(hObject,'String'));
end
% ----------------------------------------------------
% Set the value of the edit1 text component String
function edit1text_callback(hObject,eventdata)
global h;
h=str2double(get(hObject,'String'));
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -