function [im_hatch,colorlist] = applyhatch_pluscolor(h,patterns,CvBW,Hinvert,colorlist, ... dpi,hatchsc,lw) %APPLYHATCH_PLUSCOLOR Apply hatched patterns to a figure in BW or Color % APPLYHATCH_PLUSCOLOR(H,PATTERNS) creates a new figure from the figure H by % replacing distinct colors in H with the black and white % patterns in PATTERNS. The format for PATTERNS can be % a string of the characters: % '/', '\', '|', '-', '+', 'x', '.', 'c', 'w', 'k' % (see makehatch_plus.m for more details) or % a cell array of matrices of zeros (white) and ones (black) % % In addition, H can alternatively be a uint8 NxMx3 matrix of the type % produced by imread. In this case, colors in this image will be % replaced with patterns as if it was a figure. A final figure window % will be generated that displays the result. The DPI argument % discussed below will be ignored if H is an image matrix. % % APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW) binary value for choice of Color or Black % and White plots. If color is chosen the color will match that of the % current fill. 1 -> Color, anything else -> BW % % APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW,HINVERT) binary value to invert the hatch. % i.e., if it is black lines with a white background, that becomes white % lines with a black background. This can either be a scalar value or a % 1xN array equal to the length of PATTERNS. When used as an array each % PATTERNS(i) will be inverted according to Hinvert(i). 1 -> Invert, % anything else -> Non Inverted % % APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW,HINVERT,COLORS) maps the colors in the n by 3 % matrix COLORS to PATTERNS. Each row of COLORS specifies an RGB % color value. % % Note this function makes a bitmap image of H and so is limited % to bitmap output. % % Additional arguments: % % [im_hatch,colorlist] = applyhatch_plus(h,patterns,CvBW,Hinvert,colorlist,dpi,hatchsc,linewidth) % % input DPI allows specification of bitmap resolution, making plot resolution % better for printing. Ignored if H is an image matrix. % HATCHSC multiplier for hatch scale to increase size of pattern for better operation % at higher resolutions % default [] uses screen resolution as in % APPLYHATCH % LINEWIDTH A scaling factor to apply to line and dot sizes % in hatching. Defaults to 1. % output IM_HATCH RGB bitmap matrix of new figure % use IMWRITE to output in desired format % COLORLIST List of colors actually replaced. Useful info if % no colorlist initially given to function. % Colorlist will be uint8, not 0-1 scale as % originally specified. % % Example 1: % bar(rand(3,4)); % [im_hatch,colorlist] = applyhatch_pluscolor(gcf,'\-x.',0,0,[],150); % imwrite(im_hatch,'im_hatch.png','png') % % Example 2: % bar(rand(3,4)); % [im_hatch,colorlist] = applyhatch_pluscolor(gcf,'<