⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setffromimage.m

📁 Sparse Signal Representation using Overlapping Frames (matlab toolbox)
💻 M
字号:
function [F,History]=SetFfromImage(B,K,BlockSize)
% SetFfromImage    Set F as a frame of randomly selected blocks from image B.
%                  K blocks from the image are extracted, each block is reordered into
% a column vector and normalized before stored as a column in the frame F.
% Normalized: norm(f)==1 and sum(f)>0 where f is a column of F
% Also a set of training vectors may be extracted using this function.
%
% [F,History]=SetFfromImage(B,K,BlockSize);     % -----------------------------------------------------------------------------------
% Arguments:
%  F         - the frame of vectors, size NxK, N=prod(BlockSize)
%  History   - one or more strings describing how F has been made
%  B         - the image/texture a 2D matrix of numbers
%  K         - Number of frame vectors to make
%  BlockSize - The block size to use, BlockSize=[7,7]; for a 7x7 block 
% ------------------------------------------------------------------------------------

%----------------------------------------------------------------------
% Copyright (c) 2002.  Karl Skretting.  All rights reserved.
% Hogskolen in Stavanger (Stavanger University), Signal Processing Group
% Mail:  karl.skretting@tn.his.no   Homepage:  http://www.ux.his.no/~karlsk/
% 
% HISTORY:
% Ver. 1.0  25.12.2002  KS  made function based on ..\Textures\SetFt01.m
%----------------------------------------------------------------------

Mfile='SetFfromImage';
F=[];
History=[Mfile,' ',date,' empty matrix'];

if (nargin==3)
   Edge=1;
else
   disp([Mfile,': wrong number of arguments, see help.']);
   return
end

N=prod(BlockSize);
ImSize=size(B);

% start to build F
M=ceil(sqrt(K));
F=zeros(N,M*M);
m1=Edge:(ImSize(1)-Edge-BlockSize(1));   % left column of block
[temp,I]=sort(randn(length(m1),1));
m1=m1(I(1:M));
m1=sort(m1);
m2=Edge:(ImSize(2)-Edge-BlockSize(2));   % top row of block
[temp,I]=sort(randn(length(m2),1));
m2=m2(I(1:M));
m2=sort(m2);
l=0;
for i=m1
   for j=m2
      l=l+1;
      x=B(i-1+(1:BlockSize(1)),j-1+(1:BlockSize(2)));
      x=x(:);temp=x'*x;
      if (temp > 0); temp=sqrt(temp); else temp=1; end;
      if sum(x)<0; temp=-temp; end;   % change sign
      F(:,l)=x/temp;
   end
end
F=F(:,1:K);
%
History=[Mfile,' used ',int2str(K),' ',int2str(BlockSize(1)),'x',...
      int2str(BlockSize(2)),' blocks from image',...
      ' and generated F of size ',int2str(N),'x',int2str(K),'.'];

return

% test of function
[F3,H3]=SetFfromImage(randn(100),32,[4,5]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -