本课题的主要工作是使用seam+carving算法对图像进行非等比例缩放以及无缝拼接,关于seam+caring算法的理论,这里不再重复,主要见如下的参考文献(已经提供)。

下面介绍本系统的主要操作方法以及对应的函数说明:

打开图片:

选择图片:

得到如下的仿真结果:

下面开始非等比例缩放:

从上面的图中,你可以看到人物的大小基本不变,然偶人物上方的蓝天的背景基本被缩小了。这个就是非等比例缩放的效果.

无缝拼接,利用seam-curing算法对图片进行裁剪。

部分代码如下:

func_addpath();

[FileName,PathName] = uigetfile('*.*','选择图像');
FullPathName        = [PathName,'\',FileName];
Image_RGB           = imread(FullPathName);

%保存图片的相关参数信息到句柄函数handles中
handles.Image_RGB =  double(Image_RGB)/255;
handles.Idata     = (handles.Image_RGB);
handles.dispX     =  handles.Idata;
handles.rows      = size(handles.Idata,1);
handles.cols      = size(handles.Idata,2);
handles.dim       = size(handles.Idata,3);
handles.Engry     = func_gradient(handles.Idata);
handles.dispE     = handles.Engry;
handles.dispS     = zeros(handles.rows, handles.cols);

figure(1);
imshow(Image_RGB);
set(handles.edit1,'String',num2str(handles.cols));
set(handles.edit2,'String',num2str(handles.rows));

axes(handles.axes3);
imshow(Image_RGB);

guidata(hObject,handles);

%垂直Seam缩小
function RemVerSeam_Callback(hObject, eventdata, handles)
% hObject    handle to RemVerSeam (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
func_addpath();
if(handles.rows>1&&handles.cols>1)
    
    %根据梯度信息计算Seam
    handles.seam       = func_find_seam(handles.Engry);
    handles.SeamVector = func_all_seam(handles.seam);

%删除seam
    handles.Idata      = func_ReSeam(handles.Idata,handles.SeamVector);
    handles.Engry      = func_ReSeam(handles.Engry,handles.SeamVector);
    handles.seam       = func_ReSeam(handles.seam,handles.SeamVector);
    
    %更新操作后的图像大小
    handles.rows      = size(handles.Idata,1);
    handles.cols      = size(handles.Idata,2);
    handles.dim       = size(handles.Idata,3);
    
    set(handles.edit1,'String',num2str(handles.cols));
    set(handles.edit2,'String',num2str(handles.rows));
    
    handles.dispX     = func_seam_view(handles.Idata , handles.SeamVector);
    handles.dispE     = func_seam_view(handles.Engry , handles.SeamVector);
    handles.dispS     = func_seam_view(handles.seam  , handles.SeamVector);

figure(1);
    imshow(handles.dispX);
    
    guidata(hObject,handles);
end

%水平Seam缩小
function RemHorizSeam_Callback(hObject, eventdata, handles)
% hObject    handle to RemHorizSeam (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
func_addpath();
if (handles.rows>1&&handles.cols>1)

handles.Idata      = permute(handles.Idata,[2,1,3]);%旋转
    handles.Engry      = handles.Engry.';
    handles.seam       = func_find_seam(handles.Engry);
    handles.SeamVector = func_all_seam(handles.seam);

handles.Idata      = func_ReSeam(handles.Idata , handles.SeamVector);
    handles.Engry      = func_ReSeam(handles.Engry , handles.SeamVector);
    handles.seam       = func_ReSeam(handles.seam  , handles.SeamVector);
    
    handles.Idata      = permute(handles.Idata,[2,1,3]);
    handles.Engry      = handles.Engry.';
    handles.seam       = handles.seam.';
    
    handles.dispX      = permute(func_seam_view(permute(handles.Idata,[2,1,3]),handles.SeamVector),[2,1,3]);
    handles.dispE      = func_seam_view(handles.Engry.',handles.SeamVector).';
    handles.dispS      = func_seam_view(handles.seam.',handles.SeamVector).';

%更新操作后的图像大小
    handles.rows      = size(handles.Idata,1);
    handles.cols      = size(handles.Idata,2);
    handles.dim       = size(handles.Idata,3);
    
    set(handles.edit1,'String',num2str(handles.cols));
    set(handles.edit2,'String',num2str(handles.rows));
    
    figure(1);
    imshow(handles.dispX);
    guidata(hObject,handles);
end

%自动缩放
function Resize_Callback(hObject, eventdata, handles)
% hObject    handle to Resize (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
func_addpath();
%获得需要变换的图像的像素大小值
%获得需要变换的图像的像素大小值
newcols = str2double(get(handles.edit1,'String'));
newrows = str2double(get(handles.edit2,'String'));
Rcols   = handles.cols-newcols;
Rrows   = handles.rows-newrows;

if Rcols>0
    clear M
    M                 = func_removal(handles.Idata,Rcols);
    handles.Idata     = func_ReSeam(handles.Idata,M);
    handles.Engry     = func_ReSeam(handles.Engry,M);
    handles.seam      = func_find_seam(handles.Engry);
    
    %更新操作后的图像大小
    handles.rows      = size(handles.Idata,1);
    handles.cols      = size(handles.Idata,2);
    handles.dim       = size(handles.Idata,3);    
 
elseif Rcols<0
    clear M
    M                 = func_removal(handles.Idata,abs(Rcols));
    handles.Idata     = func_new_Seam(handles.Idata,M);
    handles.Engry     = func_new_Seam(handles.Engry,M);
    handles.seam      = func_find_seam(handles.Engry);
    %更新操作后的图像大小
    handles.rows      = size(handles.Idata,1);
    handles.cols      = size(handles.Idata,2);
    handles.dim       = size(handles.Idata,3);  
end

if Rrows>0
    clear M
    Y                 = permute(handles.Idata,[2,1,3]);
    M                 = func_removal(Y,Rrows);
    handles.Idata     = permute(func_ReSeam(Y,M),[2,1,3]);
    handles.Engry     = func_ReSeam(handles.Engry.',M).';
    handles.seam      = func_find_seam(handles.Engry);
    %更新操作后的图像大小
    handles.rows      = size(handles.Idata,1);
    handles.cols      = size(handles.Idata,2);
    handles.dim       = size(handles.Idata,3);  
elseif Rrows<0
    clear M
    Y                 = permute(handles.Idata,[2,1,3]);
    M                 = func_removal(Y,abs(Rrows));
    handles.Idata     = permute(func_new_Seam(Y,M),[2,1,3]);
    handles.Engry     = func_new_Seam(handles.Engry.',M).';
    handles.seam      = func_find_seam(handles.Engry);
    %更新操作后的图像大小
    handles.rows      = size(handles.Idata,1);
    handles.cols      = size(handles.Idata,2);
    handles.dim       = size(handles.Idata,3);  
end

handles.dispX     = handles.Idata;
handles.dispE     = handles.Engry;
handles.dispS     = handles.seam;
%更新操作后的图像大小
handles.rows      = size(handles.Idata,1);
handles.cols      = size(handles.Idata,2);
handles.dim       = size(handles.Idata,3);

figure(1);
imshow(handles.dispX);

set(handles.edit1,'String',num2str(handles.cols));
set(handles.edit2,'String',num2str(handles.rows));

guidata(hObject,handles);

%系统复位,图像还原
function Reset_Callback(hObject, eventdata, handles)
func_addpath();
handles.Idata = handles.Image_RGB;
handles.dispX =handles.Idata;

handles.rows  = size(handles.Idata,1);
handles.cols  = size(handles.Idata,2);
handles.dim   = size(handles.Idata,3);

handles.Engry = func_gradient(handles.Idata);
handles.dispE = handles.Engry;
handles.dispS = zeros(handles.rows,handles.cols);

figure(1);
imshow(handles.dispX);
set(handles.edit1,'String',num2str(handles.cols));
set(handles.edit2,'String',num2str(handles.rows));

guidata(hObject,handles);

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

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

function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% NewVal = get(hObject,'String');
% handles.edit1 = NewVal;
% guidata(hObject,handles);

% --- 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

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

% NewVal = str2double(get(hObject,'String'));
% handles.edit2 = NewVal;
% guidata(hObject,handles);

% --- 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 button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
func_addpath();
clc;
clear all;
close all;

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

a = str2double(get(handles.edit5,'String'));
b = str2double(get(handles.edit6,'String'));

handles.Idata = handles.Image_RGB;
handles.dispX = handles.Idata;

handles.rows  = size(handles.Idata,1);
handles.cols  = size(handles.Idata,2);
handles.dim   = size(handles.Idata,3);

Images1       = handles.Idata(1:a,:,:);
Images2       = handles.Idata(a+1:handles.rows,:,:);

Rcols   = 0;
Rrows   = round(b/2);

if Rrows>0
    clear M
    Y                 = permute(Images1,[2,1,3]);
    M                 = func_removal(Y,Rrows);
    Images1           = permute(func_ReSeam(Y,M),[2,1,3]);
    handles.Engry     = func_ReSeam(handles.Engry.',M).';
    handles.seam      = func_find_seam(handles.Engry);
    %更新操作后的图像大小
    handles.rows      = size(Images1,1);
    handles.cols      = size(Images1,2);
    handles.dim       = size(Images1,3);  
elseif Rrows<0
    clear M
    Y                 = permute(Images1,[2,1,3]);
    M                 = func_removal(Y,abs(Rrows));
    Images1           = permute(func_new_Seam(Y,M),[2,1,3]);
    handles.Engry     = func_new_Seam(handles.Engry.',M).';
    handles.seam      = func_find_seam(handles.Engry);
    %更新操作后的图像大小
    handles.rows      = size(Images1,1);
    handles.cols      = size(Images1,2);
    handles.dim       = size(Images1,3);  
end

if Rrows>0
    clear M
    Y                 = permute(Images2,[2,1,3]);
    M                 = func_removal(Y,Rrows);
    Images2           = permute(func_ReSeam(Y,M),[2,1,3]);
    handles.Engry     = func_ReSeam(handles.Engry.',M).';
    handles.seam      = func_find_seam(handles.Engry);
    %更新操作后的图像大小
    handles.rows      = size(Images2,1);
    handles.cols      = size(Images2,2);
    handles.dim       = size(Images2,3);  
elseif Rrows<0
    clear M
    Y                 = permute(Images2,[2,1,3]);
    M                 = func_removal(Y,abs(Rrows));
    Images2           = permute(func_new_Seam(Y,M),[2,1,3]);
    handles.Engry     = func_new_Seam(handles.Engry.',M).';
    handles.seam      = func_find_seam(handles.Engry);
    %更新操作后的图像大小
    handles.rows      = size(Images2,1);
    handles.cols      = size(Images2,2);
    handles.dim       = size(Images2,3);  
end

axes(handles.axes4);

finals(:,:,1) = [Images1(:,:,1);Images2(:,:,1)];
finals(:,:,2) = [Images1(:,:,2);Images2(:,:,2)];
finals(:,:,3) = [Images1(:,:,3);Images2(:,:,3)];

imshow(finals);

guidata(hObject,handles);

% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
func_addpath();
a = str2double(get(handles.edit3,'String'));
b = str2double(get(handles.edit4,'String'));

handles.Idata = handles.Image_RGB;
handles.dispX =handles.Idata;

handles.rows  = size(handles.Idata,1);
handles.cols  = size(handles.Idata,2);
handles.dim   = size(handles.Idata,3);

Images1       = handles.Idata(:,1:a,:);
Images2       = handles.Idata(:,a+1:handles.cols,:);

Rcols   = round(b/2);
Rrows   = 0;

if Rcols>0
    clear M
    M                 = func_removal(Images1,Rcols);
    Images1           = func_ReSeam(Images1,M);
    handles.Engry     = func_ReSeam(handles.Engry,M);
    handles.seam      = func_find_seam(handles.Engry);
    
    %更新操作后的图像大小
    handles.rows      = size(Images1,1);
    handles.cols      = size(Images1,2);
    handles.dim       = size(Images1,3);    
 
elseif Rcols<0
    clear M
    M                 = func_removal(Images1,abs(Rcols));
    Images1           = func_new_Seam(Images1,M);
    handles.Engry     = func_new_Seam(handles.Engry,M);
    handles.seam      = func_find_seam(handles.Engry);
    %更新操作后的图像大小
    handles.rows      = size(Images1,1);
    handles.cols      = size(Images1,2);
    handles.dim       = size(Images1,3);  
end

if Rcols>0
    clear M
    M                 = func_removal(Images2,Rcols);
    Images2           = func_ReSeam(Images2,M);
    handles.Engry     = func_ReSeam(handles.Engry,M);
    handles.seam      = func_find_seam(handles.Engry);
    
    %更新操作后的图像大小
    handles.rows      = size(Images2,1);
    handles.cols      = size(Images2,2);
    handles.dim       = size(Images2,3);    
 
elseif Rcols<0
    clear M
    M                 = func_removal(Images2,abs(Rcols));
    Images2           = func_new_Seam(Images2,M);
    handles.Engry     = func_new_Seam(handles.Engry,M);
    handles.seam      = func_find_seam(handles.Engry);
    %更新操作后的图像大小
    handles.rows      = size(Images2,1);
    handles.cols      = size(Images2,2);
    handles.dim       = size(Images2,3);  
end

A23-04

基于Seam+Carving和显著性分析的图像缩放方法MATLAB仿真相关推荐

  1. 基于基于全局差错能量函数的双目图像立体匹配算法matlab仿真,并提取图像的深度信息

    目录 1.算法概述 2.仿真效果预览 3.核心MATLAB代码预览 4.完整MATLAB程序 1.算法概述 全局的能量函数公式如下: E(f)=Edata(f)+Esmooth(f) 其中,Edata ...

  2. 论文笔记--基于 FCM 聚类的跨模态人物图像标注方法-2015

    期刊论文-基于 FCM 聚类的跨模态人物图像标注方法-2015-微型电脑应用-赵昀,张翌翀 文末附人脸标注相关论文下载地址 文章目录 摘要 技术 人脸检测与特征表示(与2012年吴伟硕士论文<跨 ...

  3. 关于通用雷达信号的时频分析与图像绘制(Matlab)

    关于通用雷达信号的时频分析与图像绘制(Matlab) 最近在研究雷达信号的调制识别,所以对通用的雷达信号种类进行了时频域上的研究,下面小结给大家,从信号的原理到matlab的时频图绘制. 信号种类 这 ...

  4. 【ISAR成像定标方法(3)—基于SGP4模型的空间目标定标方法MATLAB仿真】

    目录 前提介绍 基于SGP4模型的转速估计 基于SGP4模型的空间目标定标仿真实验 结语 前提介绍 本章内容简介:本文研究了使用双行轨道报和SGP4模型估计空间LEO目标位置信息,并根据几何关系推测目 ...

  5. 电机调速设计并用matlab仿真,终稿毕业论文设计_基于PWM控制的直流电动机调速系统设计及MATLAB仿真.doc最终版(备份存档)...

    <毕业论文_基于PWM控制的直流电动机调速系统设计及MATLAB仿真.doc>由会员分享,可免费在线阅读全文,更多与<(终稿)毕业论文设计_基于PWM控制的直流电动机调速系统设计及M ...

  6. 运用滤波反投影的方法对图像进行重建matlab仿真

    目录 1.算法描述 2.仿真效果预览 3.MATLAB部分代码预览 4.完整MATLAB程序 1.算法描述 直接由正弦图得到反投影图像,会存在严重的模糊,这是早期 CT 系统所存在的问题.傅立叶中心切 ...

  7. matlab Sellmeier拟合,rcwa 关于严格耦合波发分析光栅等的相关matlab仿真 275万源代码下载- www.pudn.com...

    文件名称: rcwa下载  收藏√  [ 5  4  3  2  1 ] 开发工具: matlab 文件大小: 392 KB 上传时间: 2014-02-22 下载次数: 41 提 供 者: 赵昊 详 ...

  8. 基于双层优化的微电网系统规划设计方法matlab程序(yalmip+cplex)

    基于双层优化的微电网系统规划设计方法matlab程序(yalmip+cplex) 参考文献:基于双层优化的微电网系统规划设计方法 摘要:规划设计是微电网系统核心技术体系之一.从分布式电源的综合优化(组 ...

  9. SVPWM仿真和基于DSP28335的PIL(处理器在环) 仿真模型(将matlab仿真算法生成代码在DSP中在线运行返回数据给Matlab)验证算法可行性和实时性

    SVPWM仿真和基于DSP28335的PIL(处理器在环) 仿真模型(将matlab仿真算法生成代码在DSP中在线运行返回数据给Matlab)验证算法可行性和实时性. 对于数字信号处理很有用. ID: ...

最新文章

  1. 使用Docker快速搭建PHP开发环境
  2. 训练LaneATT遇到CUDA_HOME环境变量问题
  3. div 自动换行_js自动打字--autotypejs
  4. 构建 RESTful Web 服务
  5. hihoCoder #1068 : RMQ-ST算法(模板)
  6. eclipse编辑js卡死解决方案
  7. teamcity mysql 配置_CentOS 7 上 TeamCity 安装
  8. oracle介质恢复的内部过程--推断与参考
  9. 今日讨论:你们测试组有公共用例库吗?
  10. mysql安装运行(centos)
  11. 手机打开电脑端网页_网站建设要把电脑端手机端都做好
  12. CAD打印后图形不显示?
  13. IPV6:移动光猫吉比特GM228-S 桥接+IPV6教程
  14. 大数据资料 下载0积分
  15. PDF添加图片(图片透明)
  16. 国产Si24R2F+2.4GHz超低功耗有源RFID无线发射芯片
  17. adb: failed to install xxx Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
  18. Python中带“symmetric_”前缀的方法的特点
  19. 基于stm32单片机的温湿度火灾检测报警仓库管理系统(实物图+源码+原理图+全套资料)
  20. 浏览器适配IE浏览器问题

热门文章

  1. Cordic的学习初步
  2. 天气小工具新增风格-默认无背景,感谢欧阳兄制作
  3. 生活随笔:保险公司来的电话
  4. UA MATH567 高维统计I 概率不等式4 亚高斯分布
  5. VC mfc 多文档程序更改子文档标题名
  6. Asp.net PageBase学习总结
  7. 图解动软代码生成器使用
  8. 图解修改Windows启动菜单命令行工具BCDEdit
  9. C# 线程池和编程实例
  10. vue token 过期处理