怎么把图形类型转变过来
本帖最后由 scott198510 于 2011-7-15 18:19 编辑怎么把真彩图片类型转换成二值显示呢? A=[2 2 2 3 3 4 4
2 2 1 1 1 4 4
6 1 1 1 1 1 4
6 1 1 1 1 1 5
6 6 1 1 1 5 5
6 6 6 6 5 5 5
6 6 6 6 5 5 5];
hold on
arrayfun(@(i)arrayfun(@(j)line([(j-0.5)*(A(i,j)~=A(i+1,j)),(j+0.5)*(A(i,j)~=A(i+1,j))],[(i+0.5)*(A(i,j)~=A(i+1,j)),(i+0.5)*(A(i,j)~=A(i+1,j))]),1:size(A,2)),1:length(A)-1)
arrayfun(@(i)arrayfun(@(j)line([(i+0.5)*(A(j,i)~=A(j,i+1)),(i+0.5)*(A(j,i)~=A(j,i+1))],[(j-0.5)*(A(j,i)~=A(j,i+1)),(j+0.5)*(A(j,i)~=A(j,i+1))]),1:length(A)),1:size(A,2)-1)
set(gca,'xlim',,'ylim',)
A=A';
arrayfun(@(i,j)text(i,j,num2str(A(i,j))),meshgrid(1:7),meshgrid(1:7)')
h=findall(gca,'type','line');
arrayfun(@(i)set(h(i),'linewidth',2),1:length(h))
set(gca,'linewidth',2) 本帖最后由 scott198510 于 2011-7-15 18:18 编辑
用两种方法画出来的效果对比图:矩阵为S1000(附件内):
置0方法画图:
6# scott198510
叠加显示不上的话,请将矩阵旋转90度,逆时针,imrotate函数试试 本帖最后由 scott198510 于 2011-7-15 18:18 编辑
现对矩阵A执行 :
最后得到的图形完全重合了 本帖最后由 qibbxxt 于 2011-2-28 16:23 编辑
由于时间有限,写了一个面向对象的程序,比较常,也没有经过优化,仅供参考
classdef ColorMatrix
properties
Matrix;
x;
y;
vertPos;
horzPos;
end
methods
function obj = ColorMatrix(Matrix, x, y)
if nargin>0
obj.Matrix = Matrix;
obj.x = x;
obj.y = y;
obj.vertPos = [];
obj.horzPos = [];
end
end
function obj = findDifferentPos(obj)
obj.vertPos = find(obj.diff_me(obj.Matrix));
obj.horzPos = find(obj.diff_me(obj.Matrix'));
end
function obj = Pos2Coor(obj)
if isempty(obj.vertPos) || isempty(obj.horzPos)
return;
end
= obj.ind2sub_me(size(obj.Matrix),obj.vertPos);
= obj.ind2sub_me(size(obj.Matrix),obj.horzPos);
obj.x = ;
obj.y = size(obj.Matrix,1)-;
end
function Plot(obj)
plot(obj.x, obj.y, 'r','LineWidth',5);
end
function obj = DisplayMatrix(obj)
display_matrix(obj.Matrix, '图形类型转变', '%d');
end
function RunPro(obj)
DisplayMatrix(obj);
obj = findDifferentPos(obj);
obj = Pos2Coor(obj);
Plot(obj);
end
end
methods(Static)
function = ind2sub_me(siz,vect)
= ind2sub(siz,vect);
x = x';
y = y';
end
function x = diff_me(mat)
x = diff(mat);
x(size(mat),length(mat)) = 0;
end
end
end
clear;clc;close all
A =[ 2 2 2 3 3 4 4
2 2 1 1 1 4 4
6 1 1 1 1 1 4
6 1 1 1 1 1 5
6 6 1 1 1 5 5
6 6 6 6 5 5 5
6 6 6 6 5 5 5];
Ma = ColorMatrix(A,[],[]);
Ma.RunPro();
页:
[1]