保存这个fig图,会得到一个.fig文件和一个.m文件。
双击fig图打开属性检查器(或者右键,选择属性检查器),找到CreatFcn,点击进入.m文件进行编辑, 在function figure1_CreateFcn(hObject, eventdata, handles)中添加如下代码:background.jpg是你需睁铅纯要的背景图片。
完成后保存。
再悉咐次打开.fig,就完成了
1.首先通过函数对图片进行读取并显示。
image = imread('杯子.jpg')
imshow(image)
运行后图片如誉隐扰图。
2.接下来对红色分量进行提取并显示。
image = imread('杯子.jpg')
imager = image(:,:,1)
imshow(imager)
庆旦3.接下来对绿色分量进行提取并显示。
image = imread('杯子.jpg')
imageg = image(:,:,2)
imshow(imageg)
4.接下来对蓝色分量进行提取并显示。
image = imread('杯子.jpg')
imageb = image(:,:,3)
imshow(imageb)
5.为了方便比较,采用sublpot函数将处理过的图片通过一个界面进行显示。
image = imread('杯子.jpg')
imager = image(:,:,1)
imageg = image(:,:,2)
imageb = image(:,:,3)
subplot(221)
imshow(imager)
title('r')
subplot(222)
imshow(imageg)
title('g')
subplot(223)
imshow(imageb)
title('b')
subplot(224)
imshow(image)
6.同携巧时,在图像处理后还可以将图像不同分量进行想加,代码如下:
image = imread('杯子.jpg')
imager = image(:,:,1)
imageg = image(:,:,2)
imageb = image(:,:,3)
subplot(221)
imshow(imager)
title('r')
subplot(222)
imshow(imageg)
title('g')
subplot(223)
imshow(imageb)
title('b')
subplot(224)
imshow(imageg+imageb+imager)
代码来自A closed form solution to Natural Image MattingA. Levin D. Lischinski and Y. Weiss
求Matting Laplacian矩阵L代码:
function [A,A1]=getLaplacian1(I,consts,epsilon,win_size)
if (~exist('epsilon','var'))
epsilon=0.0000001
end
if (isempty(epsilon))
epsilon=0.0000001
end
if (~exist('win_size','var'))
win_size=1
end
if (isempty(win_size))
win_size=1
end
neb_size=(win_size*2+1)^2
[h,w,c]=size(I)
n=hm=w
img_size=w*h
consts=imerode(consts,ones(win_size*2+1))
indsM=reshape([1:img_size],h,w)
tlen=sum(sum(1-consts(win_size+1:end-win_size,win_size+1:end-win_size)))*(neb_size^2)
row_inds=zeros(tlen ,1)
col_inds=zeros(tlen,1)
vals=zeros(tlen,1)
len=0
for j=1+win_size:w-win_size
for i=win_size+1:h-win_size
if (consts(i,j))
continue
end
win_inds=indsM(i-win_size:i+win_size,j-win_size:j+win_size)
win_inds=win_inds(:)
winI=I(i-win_size:i+win_size,j-win_size:j+win_size,:)
winI=reshape(winI,neb_size,c)
win_mu=mean(winI,1)'
win_var=inv(winI'*winI/neb_size-win_mu*win_mu' +epsilon/neb_size*eye(c))
winI=winI-repmat(win_mu',neb_size,1)
tvals=(1+winI*win_var*winI')/neb_size
row_inds(1+len:neb_size^2+len)=reshape(repmat(win_inds,1,neb_size),...
neb_size^2,1)
col_inds(1+len:neb_size^2+len)=reshape(repmat(win_inds',neb_size,1),...
neb_size^2,1)
vals(1+len:neb_size^2+len)=tvals(:)
len=len+neb_size^2
end
end
vals=vals(1:len)
row_inds=row_inds(1:len)
col_inds=col_inds(1:len)
A=sparse(row_inds,col_inds,vals,img_size,img_size)
sumA=sum(A,2)
A=spdiags(sumA(:),0,img_size,img_size)-A
return
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)