image processing - Creating a Photoshop-like black and white filter for Matlab figures -


creating grayscale images matlab figures can big pain because have scale colormaps , color limits right gray colormap picks details. i've realized photoshop very, doing this. load in image , use black , white filter, , change levels of reds, greens, blues, etc. suit details of image. see below example

here example image

i think extremely useful have function 1 can call takes in same inputs photoshop requires. function might of form

  function bwfilter(h, c) 

where c matrix takes in input of red, green, cyan, etc. percentages, , h figure handle. upon running function, figure converted black , white , either kept matlab's .fig format, or if not possible, exported png, pdf, etc. perhaps using excellent export_fig function oliver woodford.

i'm not sure how go this. can advise? of course, if wants step challenge...

what this:

function stackexchange_rgb2gray_rygcbm % http://stackoverflow.com/questions/16083685/creating-a-photoshop-like-black-and-white-filter-for-matlab-figures      function imgray = rgb2gray_rygcbm(imgrgb,coefficients)         %         % imgrgb        source rgb image         %         % coefficients  vector of color coefficients         %                   [red yellow green cyan blue magenta]         %         %                   0.0 means corresponding color         %                           not contribute resulting gray image         %         %                   1.0 means corresponding color intensity         %                           unchanged on resulting gray image         %         %                   values higher 1.0 might work if product         %                           (maximal_color_intensity * color_coefficient) <= 1         %         %                   rgb2gray_rygcbm(imgrgb,[1 1 1 1 1 1]) equivalent rgb2gray(imgrgb)         %         % author: andriy nych         %   date: 2013/04/19         %          % check fed         if length(coefficients)~=6             error('second argument must 6 elements long!');         end         % extract color information image         imghsv  = rgb2hsv(imgrgb);         imgh    = imghsv(:,:,1);         imgs    = imghsv(:,:,2);         imgv    = imghsv(:,:,3);         % prepare small stuff         coefficients(coefficients<0) = 0;         coefficients    = [ coefficients(:)' coefficients(1) ];         rygcbm          = linspace(0,1,7);         % cook "magic"         imghf           = imgh;         kk=1:6             iidx            = (rygcbm(kk)<=imgh) & (imgh<rygcbm(kk+1));             tx              = imgh(iidx);             ty              = coefficients(kk) + sin( (tx-rygcbm(kk))/(rygcbm(kk+1)-rygcbm(kk)) * pi/2 ).^2 * (coefficients(kk+1)-coefficients(kk));             imghf(iidx)     = ty;         end         % apply "magic"         imgv2   = imgv .* imghf;         imgn    = hsv2rgb( cat(3,imgh,imgs,imgv2) );         % ,         imgray  = rgb2gray(imgn);     end  % shall test code  % first generate rgb image figure; surf(peaks(64)); colormap(hsv(256)); f = getframe(gcf); close(gcf); imgrgb = f.cdata;  % create simple gui , display results mm = 0.2; figure('color','w', 'units','normalized', 'position',[0 0 1 1]+[+1 +1 -2 -2]*mm); imggray = rgb2gray(imgrgb); a1 = subplot(1,2,1);    h0 = imshow(imgrgb);    axis on;    title('original image'); a2 = subplot(1,2,2);    h1 = imshow(imggray);   axis on;    title('rgb2gray'); mm = 0.05; set(a1, 'units','normalized', 'position',[0.0 0.0 0.5 1.0]+[+1 +1 -2 -2]*mm ); set(a2, 'units','normalized', 'position',[0.5 0.0 0.5 1.0]+[+1 +1 -2 -2]*mm ); pause(1);  % convert original image different combination of coefficients coeffs = [0 0 0 0 0 0]; nsteps = 10; ic=1:6     % we'll change 1 coefficient @ time      k=0:nsteps         % modify coefficient         coeffs(ic) = k/nsteps;         % , use them image conversion         imggray = rgb2gray_rygcbm(imgrgb,coeffs);          % show result         axis(a2);         imshow(imggray);   axis on;         %set(h1,'cdata',imggray);         title(a2, sprintf('r:%5.2f y:%5.2f g:%5.2f c:%5.2f b:%5.2f m:%5.2f',coeffs) );          drawnow;         pause(.1);     end end  end 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -