0001 function [cmap] = colormapsmake(bins,fighandle)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 nargs = nargin;
0056
0057
0058 if nargs == 0
0059 bins = 64;
0060 nargs = 1;
0061 end
0062
0063
0064 if ~isstr(bins)
0065
0066 if size(bins,2) == 3
0067 map = bins;
0068 bins = size(map,1);
0069 if nargs == 1
0070 fighandle = [];
0071 end
0072 else
0073 map = [];
0074 if nargs == 2
0075 if isstr(fighandle)
0076 fighandle = bins;
0077 map = get(fighandle,'Colormap');
0078 bins = size(map,1);
0079 end
0080 else
0081 fighandle = [];
0082 end
0083 end
0084
0085 if isempty(map)
0086 red = [1 0;bins 1];
0087 green = [1 0;bins 1];
0088 blue = [1 0;bins 1];
0089 else
0090
0091
0092
0093
0094
0095
0096
0097
0098 for j = 1:3
0099 for i = 1:bins
0100 if i == 1
0101 nodes(1,:) = [1 map(1,j)];
0102 lastnode = nodes;
0103 elseif i == 2
0104 oldtempnode = [i map(2,j)];
0105 else
0106 tempnode = [i map(i,j)];
0107 if (abs((oldtempnode(2)-lastnode(2))/(oldtempnode(1)...
0108 -lastnode(1))) <= abs((tempnode(2)-lastnode(2))...
0109 /(tempnode(1)-lastnode(1)))*1.01) & ...
0110 (abs((oldtempnode(2)-lastnode(2))/...
0111 (oldtempnode(1)-lastnode(1))) >= ...
0112 abs((tempnode(2)-lastnode(2))/...
0113 (tempnode(1)-lastnode(1)))*.99)
0114
0115
0116
0117
0118
0119
0120 oldtempnode = tempnode;
0121 else
0122 nodes = [nodes;oldtempnode];
0123 lastnode = oldtempnode;
0124 oldtempnode = tempnode;
0125 end
0126 end
0127 end
0128 nodes = [nodes;bins map(bins,j)];
0129 if j == 1
0130 red = nodes;
0131 nodes = [];
0132 elseif j == 2
0133 green = nodes;
0134 nodes = [];
0135 elseif j == 3
0136 blue = nodes;
0137 nodes = [];
0138 end
0139 end
0140 end
0141
0142 mcmfighandle = figure('color','k','NumberTitle','off',...
0143 'menubar','none','Tag','ColorMap Editor');
0144
0145 if isempty(fighandle)
0146 fighandle = mcmfighandle;
0147 end
0148
0149
0150
0151
0152
0153
0154
0155 for i = 1:size(red,1)-1
0156 W = lspace(red(i,2),red(i+1,2),red(i+1,1)-red(i,1)+1);
0157 mapred(red(i,1):red(i+1,1)-1) = W(1:red(i+1,1)-red(i,1))';
0158 end
0159 mapred(red(i+1,1)) = red(i+1,2);
0160 for i = 1:size(green,1)-1
0161 W = lspace(green(i,2),green(i+1,2),green(i+1,1)-green(i,1)+1);
0162 mapgreen(green(i,1):green(i+1,1)-1) = W(1:green(i+1,1)-green(i,1))';
0163 end
0164 mapgreen(green(i+1,1)) = green(i+1,2);
0165 for i = 1:size(blue,1)-1
0166 W = lspace(blue(i,2),blue(i+1,2),blue(i+1,1)-blue(i,1)+1);
0167 mapblue(blue(i,1):blue(i+1,1)-1) = W(1:blue(i+1,1)-blue(i,1))';
0168 end
0169 mapblue(blue(i+1,1)) = blue(i+1,2);
0170 map = [mapred(:),mapgreen(:),mapblue(:)];
0171
0172
0173
0174
0175
0176 nodenum = size(red,1);
0177 subplot(3,2,1)
0178 hold on
0179 for i = 1:nodenum-1
0180 plot(red(i,1),red(i,2),'ow')
0181 line([red(i,1),red(i+1)],[red(i,2),red(i+1,2)],'color','r')
0182 end
0183 plot(red(nodenum,1),red(nodenum,2),'ow')
0184 axis([1 red(nodenum,1) 0 1])
0185 redax = gca;
0186 set(redax,'UserData',red,'tag','r','box','on','color','k',...
0187 'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
0188 'Ytick',(0:.2:1));
0189 ylabel('Red','FontSize',14)
0190
0191
0192 subplot(3,2,3)
0193 nodenum = size(green,1);
0194 hold on
0195 for i = 1:nodenum-1
0196 plot(green(i,1),green(i,2),'ow')
0197 line([green(i,1),green(i+1)],[green(i,2),green(i+1,2)],'color','g')
0198 end
0199 plot(green(nodenum,1),green(nodenum,2),'ow')
0200 axis([1 green(nodenum,1) 0 1])
0201 greenax = gca;
0202 set(greenax,'UserData',green,'tag','g','box','on','color','k',...
0203 'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
0204 'YTick',(0:.2:1));
0205 ylabel('Green','FontSize',14)
0206
0207 subplot(3,2,5)
0208 nodenum = size(blue,1);
0209 hold on
0210 for i = 1:nodenum-1
0211 plot(blue(i,1),blue(i,2),'ow')
0212 line([blue(i,1),blue(i+1)],[blue(i,2),blue(i+1,2)],'color','b')
0213 end
0214 plot(blue(nodenum,1),blue(nodenum,2),'ow')
0215 axis([1 blue(nodenum,1) 0 1])
0216 blueax = gca;
0217 set(blueax,'UserData',blue,'tag','b','box','on','color','k',...
0218 'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
0219 'YTick',(0:.2:1));
0220 ylabel('Blue','FontSIze',14)
0221
0222
0223 colormap(map)
0224 set(fighandle,'Colormap',map)
0225
0226 transax = axes('Position',[.578 .4056 .327 .2238]);
0227 hold on
0228 trans = [1 1;bins 1];
0229 nodenum = 2;
0230 cla
0231 for i = 1:nodenum-1
0232 plot(trans(i,1),trans(i,2),'ow')
0233 line([trans(i,1),trans(i+1)],[trans(i,2),trans(i+1,2)],'color','y')
0234 end
0235 plot(trans(nodenum,1),trans(nodenum,2),'ow')
0236 axis([1 trans(nodenum,1) 0 1])
0237 trans = ones(1,bins);
0238 title('luminance','color','w','FontSize',14)
0239 set(transax,'UserData',[1 1;bins 1],'tag','y','box','on','color','k',...
0240 'xcolor','w','ycolor','w','xgrid','on','ygrid','on',...
0241 'YTick',(0:.2:1))
0242 set(mcmfighandle,'UserData',[map,trans(:)],'tag',int2str(fighandle))
0243
0244
0245 cbax = axes('Position',[.578 .75 .327 .1072]);
0246 colorbar(cbax)
0247 set(cbax,'tag','cb','xcolor','w','ycolor','w',...
0248 'UserData',[size(red,1),0;...
0249 size(green,1),0;...
0250 size(blue,1),0;...
0251 red;...
0252 green;...
0253 blue])
0254
0255
0256
0257
0258 hdaxes = axes('Position',[.57 .93 .327 .05],'Visible','off',...
0259 'tag','hd','UserData',map);
0260 text(.5,0,'Colormap Editor','FontSize',16,'Color','w',...
0261 'HorizontalAlignment','center')
0262
0263
0264
0265
0266 uicontrol('style','pushbutton','string','Reset',...
0267 'Units','Normalized',...
0268 'Position',[.6 .2 .1 .06],...
0269 'Callback','ColorMapsMake(''reset'');')
0270
0271 uicontrol('style','pushbutton','string','Export',...
0272 'Units','Normalized',...
0273 'Position',[.75 .2 .1 .06],...
0274 'Callback','ColorMapsMake(''export'');')
0275
0276 uicontrol('style','pushbutton','string','Close',...
0277 'Units','Normalized',...
0278 'Position',[.6 .1 .1 .06],...
0279 'Callback','ColorMapsMake(''close'');')
0280
0281 uicontrol('Style','PushButton','string','Help',...
0282 'Units','Normalized',...
0283 'Position',[.75 .1 .1 .06],...
0284 'Callback','ColorMapsMake(''help'');')
0285
0286
0287
0288
0289
0290
0291 set(mcmfighandle,'WindowButtonDownFcn','ColorMapsMake(''down'');')
0292 set(mcmfighandle,'WindowButtonUpFcn','ColorMapsMake(''up'');')
0293 set(mcmfighandle,'WindowButtonMotionFcn','ColorMapsMake(''motion'');')
0294 set(mcmfighandle,'CloseRequestFcn','ColorMapsMake(''close'');')
0295
0296
0297
0298
0299
0300
0301
0302 else
0303 if strcmp(bins,'down')
0304 figh = gcbf;
0305 axhandle = gca;
0306 lcolor = get(axhandle,'tag');
0307 if strcmp(lcolor,'cb') | strcmp(lcolor,'hd')
0308 return
0309 end
0310 xlimits = get(axhandle,'Xlim');
0311 ylimits = get(axhandle,'Ylim');
0312 nodes = get(axhandle,'UserData');
0313 nodenum = size(nodes,1);
0314 P = get(axhandle,'CurrentPoint');
0315 X = P(1,1);
0316 Y = P(1,2);
0317 button = get(gcbf,'SelectionType');
0318 if X <= xlimits(1)-xlimits(2)*.05 | X >= xlimits(2)*1.05 | ...
0319 Y <= ylimits(1)-ylimits(2)*.07 | Y >= ylimits(2)*1.07
0320 return
0321 end
0322
0323
0324 if strcmp(button,'normal')
0325 global M_BUTTON_DOWN M_PNTS M_LINES M_TEXT
0326 ii = find(X > nodes(:,1));
0327 minnode = max(ii);
0328 ii = find(X < nodes(:,1));
0329 maxnode = min(ii);
0330 if (X - nodes(minnode,1)) > (nodes(maxnode,1)-X)
0331 if maxnode == nodenum;
0332 nodes(maxnode,2) = max(min(Y,1),0);
0333 else
0334 nodes(maxnode,1) = round(X);
0335 nodes(maxnode,2) = max(min(Y,1),0);
0336 end
0337 M_BUTTON_DOWN = maxnode;
0338 elseif (X - nodes(minnode,1)) < (nodes(maxnode,1)-X)
0339 if minnode == 1
0340 nodes(minnode,2) = max(min(Y,1),0);
0341 else
0342 nodes(minnode,1) = round(X);
0343 nodes(minnode,2) = max(min(Y,1),0);
0344 end
0345 M_BUTTON_DOWN = minnode;
0346 end
0347 cla
0348 for i = 1:nodenum-1
0349 M_PNTS(i) = plot(nodes(i,1),nodes(i,2),'ow');
0350 M_LINES(i) = line([nodes(i,1),nodes(i+1)],...
0351 [nodes(i,2),nodes(i+1,2)],'color',lcolor);
0352 end
0353 M_PNTS(i+1) = plot(nodes(nodenum,1),nodes(nodenum,2),'ow');
0354
0355 M_TEXT = text(0,1.05,...
0356 [' ',int2str(nodes(M_BUTTON_DOWN,1)),', ',...
0357 num2str(nodes(M_BUTTON_DOWN,2),2)],...
0358 'Color','w','clipping','off',...
0359 'VerticalAlignment','bottom',...
0360 'FontSize',10);
0361
0362 axis([1 nodes(nodenum,1) 0 1])
0363
0364
0365 elseif strcmp(button,'extend')
0366 global M_BUTTON_DOWN M_PNTS M_LINES M_TEXT
0367
0368 ii = find(X > nodes(:,1));
0369 minnode = max(ii);
0370 ii = find(X < nodes(:,1));
0371 maxnode = min(ii);
0372 nodes = [nodes(1:minnode,:);[round(X),max(min(Y,1),0)];...
0373 nodes(maxnode:nodenum,:)];
0374 nodenum = size(nodes,1);
0375 M_BUTTON_DOWN = minnode+1;
0376 cla
0377 for i = 1:nodenum-1
0378 M_PNTS(i) = plot(nodes(i,1),nodes(i,2),'ow');
0379 M_LINES(i) = line([nodes(i,1),nodes(i+1)],...
0380 [nodes(i,2),nodes(i+1,2)],'color',lcolor);
0381 end
0382 M_PNTS(i+1) = plot(nodes(nodenum,1),nodes(nodenum,2),'ow');
0383 M_TEXT = text(0,1.05,...
0384 [' ',int2str(nodes(M_BUTTON_DOWN,1)),', ',...
0385 num2str(nodes(M_BUTTON_DOWN,2),2)],...
0386 'Color','w','clipping','off',...
0387 'VerticalAlignment','bottom',...
0388 'FontSize',10);
0389
0390 axis([1 nodes(nodenum,1) 0 1])
0391
0392 elseif strcmp(button,'alt')
0393 ii = find(X > nodes(:,1));
0394 minnode = max(ii);
0395 ii = find(X < nodes(:,1));
0396 maxnode = min(ii);
0397 if (X - nodes(minnode,1)) > (nodes(maxnode,1)-X)
0398 if maxnode < nodenum;
0399 nodes = [nodes(1:maxnode-1,:);nodes(maxnode+1:nodenum,:)];
0400 end
0401 elseif (X - nodes(minnode,1)) < (nodes(maxnode,1)-X)
0402 if minnode > 1
0403 nodes = [nodes(1:minnode-1,:);nodes(minnode+1:nodenum,:)];
0404 end
0405 end
0406 nodenum = size(nodes,1);
0407 cla
0408 for i = 1:nodenum-1
0409 plot(nodes(i,1),nodes(i,2),'ow')
0410 line([nodes(i,1),nodes(i+1)],[nodes(i,2),nodes(i+1,2)],'color',lcolor)
0411 end
0412 plot(nodes(nodenum,1),nodes(nodenum,2),'ow')
0413 axis([1 nodes(nodenum,1) 0 1])
0414 end
0415 set(axhandle,'UserData',nodes)
0416
0417
0418
0419
0420
0421 elseif strcmp(bins,'up')
0422 figh = gcbf;
0423 global M_TEXT
0424 delete(M_TEXT)
0425 clear global M_BUTTON_DOWN M_LINES M_PNTS M_TEXT
0426 UserData = get(figh,'UserData');
0427 fighandle = str2num(get(figh,'tag'));
0428 axhandle = gca;
0429 nodes = get(axhandle,'UserData');
0430 tagval = get(axhandle,'tag');
0431 if strcmp(tagval,'cb') | strcmp(tagval,'hd')
0432 return
0433 end
0434 for i = 1:size(nodes,1)-1
0435 W = lspace(nodes(i,2),nodes(i+1,2),nodes(i+1,1)-nodes(i,1)+1);
0436 map(nodes(i,1):nodes(i+1,1)-1) = W(1:nodes(i+1,1)-nodes(i,1))';
0437 end
0438 map(nodes(i+1,1)) = nodes(i+1,2);
0439 if strcmp(tagval,'r')
0440 UserData(:,1) = map';
0441 elseif strcmp(tagval,'g')
0442 UserData(:,2) = map';
0443 elseif strcmp(tagval,'b')
0444 UserData(:,3) = map';
0445 elseif strcmp(tagval,'y')
0446 UserData(:,4) = map';
0447 end
0448 set(figh,'UserData',UserData,'Colormap',...
0449 UserData(:,1:3).*(UserData(:,4)*ones(1,3)))
0450 if fighandle ~= figh
0451 set(fighandle,'Colormap',UserData(:,1:3).*(UserData(:,4)*ones(1,3)))
0452 end
0453
0454
0455 elseif strcmp(bins,'motion')
0456 global M_BUTTON_DOWN M_LINES M_PNTS M_TEXT
0457 if isempty(M_BUTTON_DOWN)
0458 return
0459 end
0460 axhandle = gca;
0461 nodes = get(gca,'UserData');
0462 tagval = get(gca,'tag');
0463 P = get(axhandle,'CurrentPoint');
0464 X = P(1,1);
0465 Y = P(1,2);
0466 nodenum = size(nodes,1);
0467 if M_BUTTON_DOWN == 1 | M_BUTTON_DOWN == nodenum;
0468 nodes(M_BUTTON_DOWN,2) = max(min(Y,1),0);
0469 else
0470 nodes(M_BUTTON_DOWN,1) = max(nodes(M_BUTTON_DOWN-1,1), ...
0471 min(nodes(M_BUTTON_DOWN+1,1),round(X)));
0472 nodes(M_BUTTON_DOWN,2) = max(min(Y,1),0);
0473 end
0474
0475 delete(M_PNTS(M_BUTTON_DOWN))
0476 M_PNTS(M_BUTTON_DOWN) = plot(nodes(M_BUTTON_DOWN,1),...
0477 nodes(M_BUTTON_DOWN,2),'ow');
0478 if M_BUTTON_DOWN > 1
0479 delete(M_LINES(M_BUTTON_DOWN-1))
0480 M_LINES(M_BUTTON_DOWN-1) = line([nodes(M_BUTTON_DOWN-1,1),...
0481 nodes(M_BUTTON_DOWN,1)],...
0482 [nodes(M_BUTTON_DOWN-1,2),nodes(M_BUTTON_DOWN,2)],'color',tagval);
0483 end
0484 if M_BUTTON_DOWN < nodenum
0485 delete(M_LINES(M_BUTTON_DOWN))
0486 M_LINES(M_BUTTON_DOWN) = line([nodes(M_BUTTON_DOWN,1),...
0487 nodes(M_BUTTON_DOWN+1,1)],...
0488 [nodes(M_BUTTON_DOWN,2),nodes(M_BUTTON_DOWN+1,2)],'color',tagval);
0489 end
0490
0491 delete(M_TEXT)
0492 M_TEXT = text(0,1.05,...
0493 [' ',int2str(nodes(M_BUTTON_DOWN,1)),', ',...
0494 num2str(nodes(M_BUTTON_DOWN,2),2)],...
0495 'Color','w','clipping','off',...
0496 'VerticalAlignment','bottom',...
0497 'FontSize',10);
0498
0499 axis([1 nodes(nodenum,1) 0 1])
0500 set(axhandle,'UserData',nodes)
0501
0502 elseif strcmp(bins,'export')
0503 fig = gcbf;
0504 pos = get(fig,'Position');
0505 figx = 400;
0506 figy = 200;
0507 figh = figure('Units','pixels',...
0508 'Position',...
0509 [pos(1)+pos(3)/2-figx/2 pos(2)+pos(4)/2-figy/2 figx figy],...
0510 'Resize','off','CloseRequestFcn','','menubar','none',...
0511 'numbertitle','off');
0512 uicolor = get(figh,'Color');
0513
0514
0515 uicontrol('Style','Text','Units','Pixels',...
0516 'String','Output Colormap to Desktop Variable:',...
0517 'Position',[20 figy-40 300 22],'HorizontalAlignment','left',...
0518 'FontSize',14,'BackGroundColor',uicolor)
0519
0520
0521 ui1 = uicontrol('Style','Edit','Units','Pixels',...
0522 'String','cmap','FontSize',12,...
0523 'Position',[120 figy-100 150 30]);
0524
0525 TIMESTRING = ['[OBJ1,FIGH1] = gcbo;',...
0526 'OBJHAN = get(OBJ1,''UserData'');',...
0527 'LAB1 = get(OBJHAN(1),''string'');',...
0528 'DATA1 = get(OBJHAN(2),''Colormap'');',...
0529 'eval([LAB1,'' = DATA1;'']);',...
0530 'delete(FIGH1);',...
0531 'clear OBJ1 FIGH1 OBJHAN DATA1 LAB1'];
0532
0533
0534 uicontrol('Style','PushButton','Units','Pixels',...
0535 'String','OK','FontSize',14,...
0536 'Position',[figx/4-20 10 65 30],...
0537 'UserData',[ui1 fig],'Callback',TIMESTRING)
0538
0539 TIMESTRING = ['[OBJ1,FIGH1] = gcbo;',...
0540 'delete(FIGH1);',...
0541 'clear OBJ1 FIGH1;'];
0542
0543
0544 uicontrol('Style','PushButton','Units','Pixels',...
0545 'String','Cancel','FontSize',14,...
0546 'Position',[3*figx/4-20 10 65 30],...
0547 'Callback',TIMESTRING)
0548
0549 elseif strcmp(bins,'help')
0550
0551 helpstr = sprintf(['Left Button - move RGB node\n',...
0552 'Middle Button - add node to RGB\n',...
0553 'Right Button - remove node (>2)\n\n',...
0554 'Export button - assign colormap to variable']);
0555
0556 help = helpdlg(helpstr,'ColorMap HELP');
0557
0558
0559 elseif strcmp(bins,'close')
0560 figh = gcbf;
0561 clear global M_BUTTON_DOWN M_LINES M_PNTS M_TEXT
0562 delete(figh)
0563
0564 elseif strcmp(bins,'reset')
0565 fighandle = gcbf;
0566 obj = findobj('tag','hd','parent',fighandle);
0567 map = get(obj,'UserData');
0568 set(fighandle,'Colormap',map,...
0569 'UserData',[map , ones(size(map,1),1)])
0570
0571 obj = findobj('tag','cb','parent',fighandle);
0572 nodes = get(obj,'UserData');
0573 red = nodes(4:nodes(1,1)+3,:);
0574 green = nodes(nodes(1,1)+4:nodes(1,1)+nodes(2,1)+3,:);
0575 blue = nodes(nodes(1,1)+nodes(2,1)+4:nodes(1,1)+nodes(2,1)+...
0576 nodes(3,1)+3,:);
0577
0578 obj = findobj('tag','r','parent',fighandle);
0579 axes(obj)
0580 cla
0581 nodenum = nodes(1,1);
0582 for i = 1:nodenum-1
0583 plot(red(i,1),red(i,2),'ow')
0584 line([red(i,1),red(i+1)],[red(i,2),red(i+1,2)],'color','r')
0585 end
0586 plot(red(nodenum,1),red(nodenum,2),'ow')
0587 set(obj,'UserData',red)
0588
0589 obj = findobj('tag','g','parent',fighandle);
0590 axes(obj)
0591 cla
0592 nodenum = nodes(2,1);
0593 for i = 1:nodenum-1
0594 plot(green(i,1),green(i,2),'ow')
0595 line([green(i,1),green(i+1)],[green(i,2),green(i+1,2)],'color','g')
0596 end
0597 plot(green(nodenum,1),green(nodenum,2),'ow')
0598 set(obj,'UserData',green)
0599
0600 obj = findobj('tag','b','parent',fighandle);
0601 axes(obj)
0602 cla
0603 nodenum = nodes(3,1);
0604 for i = 1:nodenum-1
0605 plot(blue(i,1),blue(i,2),'ow')
0606 line([blue(i,1),blue(i+1)],[blue(i,2),blue(i+1,2)],'color','b')
0607 end
0608 plot(blue(nodenum,1),blue(nodenum,2),'ow')
0609 set(obj,'UserData',blue)
0610
0611 obj = findobj('tag','y','parent',fighandle);
0612 axes(obj)
0613 cla
0614 trans = [1 1;size(map,1) 1];
0615 nodenum = 2;
0616 for i = 1:nodenum-1
0617 plot(trans(i,1),trans(i,2),'ow')
0618 line([trans(i,1),trans(i+1)],[trans(i,2),trans(i+1,2)],'color','y')
0619 end
0620 plot(trans(nodenum,1),trans(nodenum,2),'ow')
0621 set(obj,'UserData',trans)
0622 figh = str2num(get(fighandle,'tag'));
0623 if figh~=fighandle
0624 set(figh,'Colormap',map)
0625 end
0626 end
0627 end
0628
0629
0630 return
0631
0632
0633
0634
0635
0636 function out = lspace(x,y,N)
0637
0638
0639
0640
0641
0642
0643 out = [x+(0:N-2)*(y-x)/(N-1) y];
0644
0645 return