• 大小: 5.9MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-23
  • 语言: Matlab
  • 标签: seamCarving  matlab  gui  

资源简介

在matlab里面直接运行seamCarving_GUI.m就行,browse可以输入源图片,运行结果可以直接保存。

资源截图

代码片段和文件信息

function [newImgnewImg2mask] = addSeam( img seam  type img2 mask)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%addSeam function: duplicate given seam in the input image (img)
%Usage:
%    newImg = addSeam( img seam‘v‘); %add vertical seam to the image
%    newImg = addSeam( img seam‘v‘); %add horizontal seam to the image
%   [newImgseamImg]=addSeam(imgseam‘v‘); %here you receive seamImg which
%   contains the same image but with a colored (random color) seam on it.
%   [newImgseamImg]=addSeam(image1seam‘v‘image2); %here you receive seamImg
%   which contains image2 but with a colored (random color). Note: image2
%   should have the same dimensions of image1.
%Input:
%   -img: input image
%   -seam: the interesting seam that is extracted from getSeams function
%   -type: ‘H‘ for horizontal seams - ‘V‘ for vertical seams
%   -img2: if you want to draw the new seam on another image 
%   (with the same dimensions of img object) use it. Otherwise you can
%   use the same image object for both img and img2. (default img2=img).
%   -mask: markup mask 
%Output:
%   -newImg: new image after adding the seam
%   -newImg2: new image after adding noticable seam
%   -mask: markup mask after adding new pixels
%Citation: Avidan Shai and Ariel Shamir. “Seam carving for content-aware
%image resizing. ACM Transactions on graphics (TOG). Vol. 26. No. 3.
%ACM 2007“
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Author: Mahmoud Afifi York University.

if nargin<3
    error(‘Too few input arguments‘);
elseif nargin<4 
    img2=img;
    mask=zeros(size(img1)size(img2));
elseif nargin<5
    mask=zeros(size(img1)size(img2));
end

switch lower(type)
    case ‘h‘
        newSize=[size(img1)+1size(img2)]; %new size
        T=0; %no transpose
    case ‘v‘
        %transpose img and seam
        img_=zeros(size(img2)size(img1)size(img3)); %memory allocation
        img_2=zeros(size(img22)size(img21)size(img23)); %memory allocation
        
        for c=1:size(img3)
            img_(::c)=img(::c)‘; %image transpose
            img_2(::c)=img2(::c)‘; %image transpose
        end
        img=img_;
        img2=img_2;
        mask=mask‘;
        clear img_ img_2; %delete temp obj
        newSize=[size(img1)+1size(img2)]; %get new image‘s size
        s_(1:2)=seam(1:1); %transpose seam as well
        s_(1:1)=seam(1:2);
        seam=s_;
        clear s_; %delete temp object
        T=1; %raise transpose flag
end

%convert indices to linear indices
linearInd=sub2ind([size(img1)size(img2)] seam(::1) seam(::2));
C=sort(cat(2[1:size(img1)*size(img2)]linearInd)); %doublicate seam indicies
newInd=zeros(size(linearInd)); %memory allocation
for i=1:length(linearInd)
    ind=find(C==linearInd(i)); %get the location of interesting pixels in the new image
    newInd(i)=ind(1); %take first

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件       82587  2017-04-02 18:28  street_result.jpg
     文件        1685  2017-04-03 02:40  test_code.m
     文件      133909  2017-04-02 17:45  test1.jpg
     文件       27905  2017-04-02 17:55  test1_result_result.jpg
     文件      498054  2008-11-03 00:22  Van.bmp
     文件      263054  2017-04-02 18:12  Van_result0.bmp
     文件       89149  2017-04-02 18:35  van_seams.jpg
     文件      139709  2017-04-02 15:51  york.jpg
     文件       43346  2017-04-02 18:19  york_result4.jpg
     文件        5032  2017-04-02 16:53  addSeam.m
     文件         342  2017-04-02 15:16  addSeams.m
     文件        7117  2017-04-02 15:06  createMap.m
     文件         707  2017-04-01 14:28  getBestSeam.asv
     文件         988  2017-04-02 16:50  getBestSeam.m
     文件         702  2017-04-02 16:09  getGradient.m
     文件        3267  2017-04-02 01:24  getSeams.m
     文件     1179541  2017-04-19 14:16  logo.jpg
     文件      564054  2008-11-03 00:21  Ocean.bmp
     文件      240054  2017-04-02 18:20  ocean_result.bmp
     文件     3252398  2017-04-19 14:06  ReadMe.pdf
     文件         114  2017-04-02 18:08  Readme.txt
     文件        2026  2017-04-02 10:43  removeSeam.asv
     文件        2716  2017-04-02 17:17  removeSeam.m
     文件         338  2017-04-02 14:18  removeSeams.m
     文件        2334  2017-04-02 17:07  seamCarving.asv
     文件        2334  2017-04-02 17:23  seamCarving.m
     文件       30552  2017-04-02 16:03  seamCarving_GUI.fig
     文件       10977  2017-04-19 14:18  seamCarving_GUI.m
     文件       78704  2017-04-02 18:24  street.jpg
     文件        1518  2017-04-19 02:24  license.txt

评论

共有 条评论