[Index for tmp_for_tar/graphics] [Return to Master Index]

pixset

(tmp_for_tar/graphics/pixset.m)


Function Synopsis

im = pixset (vxy, sz, bounds)

Help text

       im = pixset ( vxy, sz, bounds=sz )

 vxy == [v;x;y] (3xP, prefered) or vxy = [v,x,y]

 v      : P     : Values of pixels (x(i),y(i)) of im.

 x,y    : P     : Coordinates, not necessarily integer or in 1:W and
                  1:H. 
 sz     : 2     : Size [H,W] of image
 bounds : 2 x 2 : map coordinates x,y from the rectangle
                  [bounds(1,1):bounds(1,2)] x [bounds(2,1):bounds(2,2)] to
                  the rectangle [1:H] x [1:W]

 im     : H x W : Image such that sum (im(:)) == sum (v). More precisely,
                  each value v(i) is distributed to the four integer pixel
                  coordinates that surround x(i),y(i).

 Coordinates outside 1:W x 1:H are altogether ignored.

 Last modified: September 2000



Listing of function file tmp_for_tar/graphics/pixset.m

##       im = pixset ( vxy, sz, bounds=sz )
##
## vxy == [v;x;y] (3xP, prefered) or vxy = [v,x,y]
##
## v      : P     : Values of pixels (x(i),y(i)) of im.
##
## x,y    : P     : Coordinates, not necessarily integer or in 1:W and
##                  1:H. 
## sz     : 2     : Size [H,W] of image
## bounds : 2 x 2 : map coordinates x,y from the rectangle
##                  [bounds(1,1):bounds(1,2)] x [bounds(2,1):bounds(2,2)] to
##                  the rectangle [1:H] x [1:W]
##
## im     : H x W : Image such that sum (im(:)) == sum (v). More precisely,
##                  each value v(i) is distributed to the four integer pixel
##                  coordinates that surround x(i),y(i).
##
## Coordinates outside 1:W x 1:H are altogether ignored.

## Author:        Etienne Grossmann  <etienne@isr.ist.utl.pt>
## Last modified: September 2000

function im = pixset (vxy, sz, bounds)

if nargin<2 || nargin>3 ,

  printf ("pixset : %i arguments found. I want 2 or 3\n",nargin);
  return
end

				# Make vxy 3 x P
if rows (vxy) != 3, 
  if columns (vxy) != 3,
    printf ("pixset : argument vxy has size %i x %i\n",size(vxy));
    keyboard
  end
  vxy = vxy';
end
sz = sz(:)';

P = columns (vxy);

if nargin == 3,
  if any (size (bounds) != 2),
    printf ("pixset : size (bounds) == [%i,%i] != [2,2]\n",size (bounds));
    keyboard
  end
				# map [bounds(i,1):bounds(i,2)] to [0,1]
  vxy(2:3,:) = (vxy(2:3,:)-bounds(:,1)*ones(1,P)).* \
      (((sz-1)./diff (bounds'))'*ones(1,P));
				# Map to 1:sz
  ## vxy(2:3,:) .*= (sz - 1)*ones(1,P) ;
  vxy(2:3,:) += 1 ;
end



v = vxy(1,:) ;
coords = vxy([2,3],:);

im = zeros (sz);

				# Round almost integer coordinates
if ! isempty( rnd = find (abs(round(coords)-coords) < sqrt(eps)) ),
  coords(rnd) = round( coords(rnd) ) ; 
end

				# Coords that are within image boundaries
ok = find( all( coords>=1 & coords<=sz([2,1])'*ones(1,P) ) ) ;



				# Those coordinates are not integer
tmp = any ( abs (rem (coords(:,ok),1) ) >= sqrt(eps) ) ;
fracc = ok( find (tmp) ) ;
intc = ok( find (1-tmp) ) ;

if ! isempty (fracc),
  
  FP = length(fracc) ;
				# Integer coordinates (in 1:sz(2) and
				# 1:sz(1)). 
  c1 = floor (coords(:,fracc) ) ;
  c2 = kron ([0 0 1 1;0 1 0 1], ones(1,FP) ) + [c1,c1,c1,c1] ;
				# These should correspond to zero weights
  if ! isempty (tmp = find ( c2 > sz([2,1])'*ones(1,4*FP) ) ),
    c2( tmp ) = 1 ;
    ## printf ("pixset : Whoa!! \n");
    ## keyboard
  end

  ## c3 = reshape (ind2sub ( sz, c2(2,:), c2(1,:)), FP, 4);

				# Weights for interpolation
  w1 = 1 - coords(:,fracc) + c1 ;
  w2 = [ w1(1,:).*w1(2,:), w1(1,:).*(1-w1(2,:)), \
	(1-w1(1,:)).*w1(2,:), (1-w1(1,:)).*(1-w1(2,:)) ] ;

  ## v2 = reshape (w2 .* [v,v,v,v], FP, 4);

  ## 				# Goddam loop! Don't know how to vectorize
  ## 				# it.
  ## for i=fracc, im(c3(i,:)) += v2(i,:); end
  ## Fortunately there was Dirk Laurie's mail to octave-help (2000/08/03)
  ## im = loop_add (im, c3, v2) ;
  ## keyboard
  im = loop_add (im, ind2sub (sz, c2(2,:), c2(1,:)), \
		 w2 .* kron (ones(1,4),v(fracc)));
end
## keyboard
if ! isempty (intc),
				# Those are integer
  coords(:,intc) = round(coords(:,intc)) ;
  ## c4 = ind2sub ( sz, coords(2,intc), coords(1,intc) ) ;
  ## v4 =  v(intc);
  ## for i=c4, im(i) += v4(i); end
  ## im = loop_add (im, c4, v4);
  im = loop_add (im,ind2sub (sz, coords(2,intc), coords(1,intc)), v(intc));
end


Produced by oct2html on Sun Sep 3 15:55:58 2000
Cross-Directory links are: ON