function [out] = myhistimage(in)
% Copyright 2009 The MathWorks, Inc.
persistent bitmapHandle;
if ishandle(bitmapHandle)
figure(bitmapHandle);
set(bitmapHandle, 'Visible', 'off');
cla;
else
bitmapHandle = figure('Visible', 'off');
set(bitmapHandle, 'Color', [1 1 1]);
set(bitmapHandle, 'PaperPositionMode', 'auto');
end;
a = get(bitmapHandle, 'Position');
s = size(in);
a(3) = s(1);
a(4) = s(2);
[X, count] = imhist(in);
stem(count, X, '-', '.');
axis tight;
set(bitmapHandle, 'Position', a);
pixels = hardcopy(bitmapHandle,'-dOpenGL','-r0');
% Size of the bitmap produced by hardcopy may be larger than that
% specified by the figure width & height.
% Also transpose to get the correct bitmap orientation for .ToVector
for i = 3:-1:1,
pixs(:,:,i) = pixels(1:s(2),1:s(1),i)'; %#ok
end;
out = rgb2gray(pixs);