資源簡介
本源代碼來自于網站。代碼能夠在讀入的圖片中進行直線、折線的繪制,并能夠控制端點標記。這個代碼彌補了matlab在原圖中繪制圖形的缺陷。matlab plot函數繪制的線段,并沒有改變讀入圖片的數據,直接保存圖片的矩陣數據,不會保留繪制的直線。利用print、saveas 等函數保存厚的圖片尺寸和以前大小不同,而且保存的圖片存在空白邊框問題。該代碼完美解決了這一問題。
代碼片段和文件信息
function?I=bitmapplot(xyIbackgroundoptions)
%?BITMAPPLOT?Linear?plot?in?bitmap.
%
%?Iplot=bitmapplot(xyIbackgroundoptions)
%
%?inputs
%???x?:?a?vector?with?x?values
%???y?:?a?vector?with?y?values?with?same?length?as?x?
%???Ibackground:?the?bitmap?used?as?background?when?a?m?x?n?x?3?matrix
%???????color?plots?are?made?when?m?x?n?a?greyscale?plot.
%???options:?struct?with?options?such?as?color
%?
%?outputs
%???Iplot:?The?bitmap?containing?the?plotted?lines
%
%?note
%???Colors?are?always?[r(ed)?g(reen)?b(lue)?a(pha)]?with?range?0..1.
%???when?Ibackground?is?grayscale?the?mean?of?rgb?is?used?as?grey?value.
%
%?options
%???options.Color:?The?color?of?the?line.
%???options.FillColor:?If?this?color?is?set?the?region?between?
%??????????the?x?and?y?coordnates?will?be?filled?with?this?color.
%???options.LineWidth:?Thickness?of?the?line?in?pixels?123..n
%???options.Marker:?The?marker?type:?‘o‘?‘+‘?or?‘*‘.
%???options.MarkerColor:?The?color?of?the?markers?used.
%???options.MarkerSize:?The?size?of?the?markers?used
%
%?example
%???%?Make?empty?bitmap
%???I?=?zeros([320?256?3]);
%???
%???%?Add?a?line
%???x=rand(110)*50+50;?y=linspace(151210);
%???I=bitmapplot(xyI);
%
%???%?Add?a?thick?red?line
%???x=rand(110)*50+100;?y=linspace(125610);
%???I=bitmapplot(xyIstruct(‘LineWidth‘5‘Color‘[1?0?0?1]));
%
%???%?Add?a?line?with?markers
%???x=rand(110)*50+150;?y=linspace(125610);
%???I=bitmapplot(xyIstruct(‘Marker‘‘*‘‘MarkerColor‘[1?0?1?1]‘Color‘[1?1?0?1]));
%
%???%?Add?a?filled?polygon
%???x=[1?100?30?100]+200;?y=[30?1?250?200];
%???I=bitmapplot(xyIstruct(‘FillColor‘[0?1?0?0.5]‘Color‘[1?1?0?1]));
%
%???%?Add?a?filled?polygon?on?top
%???x=[30?80?70?120]+200;?y=[30?1?250?200];
%???I=bitmapplot(xyIstruct(‘FillColor‘[1?0?0?0.5]‘Color‘[1?0?0?1]));
%
%???lines={‘Plot?Test‘‘BitmapPlot?version?1.2‘};
%???%?Plot?text?into?background?image
%???I=bitmaptext(linesI[1?1]struct(‘Color‘[1?1?1?1]));
%???
%???%?Show?the?bitmap
%???figure?imshow(I);
%
%?Function?is?written?by?D.Kroon?University?of?Twente?(April?2009)
%?Process?inputs
defaultoptions=struct(‘Color‘[0?0?1?1]‘FillColor‘[]‘LineWidth‘1‘Grid‘[]‘MarkerColor‘[1?0?0?1]‘Marker‘[]‘MarkerSize‘6);
if(~exist(‘options‘‘var‘))?
????options=defaultoptions;?
else
????tags?=?fieldnames(defaultoptions);
????for?i=1:length(tags)
?????????if(~isfield(optionstags{i}))??options.(tags{i})=defaultoptions.(tags{i});?end
????end
????if(length(tags)~=length(fieldnames(options)))?
????????warning(‘register_images:unknownoption‘‘unknown?options?found‘);
????end
end
%?The?function?works?with?double?values?(store?class?for?ouput)
Classb=class(Ibackground);
Ibackground=im2double(Ibackground);
%?x?and?y?to?row?vectors
x=round(x(:))‘;?y=round(y(:))‘;
%?Make?line?marker?an?fill?bitmap
I_line=zeros([size(Ibackground1)?size(Ibackground2)]);
I_marker=zeros([size(Ibackground1)?size(Ibac
評論
共有 條評論