%
% i2bdbx.m
%
% input image of blob labels.  Process for display:
%    - Full Scale Contrast Stretch
%    - Invert scaled Blob Colors
%    - add edges between the blobs
%
% jph 20 April 2002
%    01/20/14: took out some loops to make it run faster. jph
%

function [y] = i2bdbx(x,size)

%
% allocate output image y
%
y = zeros(size,size);

%
% Find min, max, and scale factor and do full-scale stretch.
%
xMax = max(max(x));
xMin = min(min(x));
ScaleFactor = 255.0 / (xMax - xMin);
y = 255 - floor( (x - xMin) * ScaleFactor);

% 
% Since there will generally be more than 256 blobs, we will invert the
% blob image and put approximate edges between the labeled regions to
% make it easier to look at the "blob" image.
% 
for row=1:size
  for col=1:size
    if ((row > 1) & (col > 1))
      if ((x(row,col) ~= x(row,col-1)) | (x(row,col) ~= x(row-1,col)))
        % this pixel is on the boundary btwn 2 blobs: make it black
        y(row,col) = 0;
      end
    end
  end
end

%
% Also, let's add a border to the image; since we inverted it it may be
%    mostly white -- and a border will make it look better when we print.
% 
y(1,1:size) = 0;
y(size,1:size) = 0;
y(1:size,1) = 0;
y(1:size,size) = 0;

return;
