matrix show , grain boundaries

23 次查看(过去 30 天)
how can i show a matrix like this photo with black line boundaries ?
  2 个评论
KSSV
KSSV 2021-5-4
What data you have? You need to have a look on voronoi.
DGM
DGM 2021-5-4
If you're going to ask the same question three times, why do you provide even less information now?
Now I'm reluctant to even answer it if it's just going to get deleted. If all you have is an indexed image, apply edge finding techniques, combine the images. You can keep it indexed or convert it to RGB. Look up fspecial(), imfilter(), edge(), ind2rgb(), colormap(), imshow().

请先登录,再进行评论。

采纳的回答

DGM
DGM 2021-5-5
编辑:DGM 2021-5-6
Your prior questions suggest that you already have an image to start with. A crude way to add lines to it is to just use edge finding methods. In this example, I'm just using an RGB image. You can do the same with an indexed image, but if you want it to display neatly with distinct colors, you'll have to figure out a colormap that does so (e.g. colorcube or a custom map).
inpict = imread('vdiag.png'); % this is rgb, uint8
emap = any(edgemap(inpict),3); % find edges
emap(:,[1:3 end-2:end]) = 1; % add border around image
emap([1:3 end-2:end],:) = 1;
% thin the edges and the dilate so it has uniform width
emap = imdilate(bwmorph(emap,'thin','Inf'),ones(3));
outpict = inpict.*uint8(~emap); % make edge regions zero
imshow(outpict) % show it
The function edgemap() is from MIMT:
If you don't want to use that, you can use any other method for edgefinding by gradient approximation. That can be done with fspecial+imfilter and some math, or you can use edge().
emap = zeros(size(inpict));
for c = 1:size(inpict,3)
emap(:,:,c) = edge(inpict(:,:,c),'sobel');
end
emap = any(emap,3);
Of course, that still requires IPT, where MIMT does not. If IPT is truly an issue, MIMT also has alternatives for imdilate() and bwmorph().
  17 个评论
HG
HG 2021-6-11
There are 3 problems:
1- The size of small matrices changes
2- The matrix apparently becomes three-dimensional.
3- I want to use hot colormap so that from the least number to the most number of the matrix is shown with colors in the hot colormap range , i.e, number 1 with black color(hot colormap) and number 5 with white color and others between them base on colormap.
Are these problems solvable?
DGM
DGM 2021-6-11
编辑:DGM 2021-6-11
If there are to be lines drawn between regions, the size of small images must change, otherwise there's nowhere to put the lines. Consider the image [1 1; 2 2; 3 3]. You'd need 4 horizontal lines and 2 vertical lines. That's more pixels than there even are in the image. Even for slightly larger images, the minimal line width would still cover large portions of the regions and distort their apparent geometry.
The output matrix is RGB. That's why it's 3D. You could use a different colormap using ind2rgb() just the same:
% just incorporate the lines into the indexed image
inpict(emap) = max(inpict(:))+1;
inpict = inpict-1; % uint8 indexed images start at 0
% build a custom colormap from hot()
% adjust n as needed for other images
n = 100;
cmap = hot(double(max(inpict(:)))*n+1);
cmap = cmap(1:n:end,:)
outpict = ind2rgb(inpict,cmap);
or you could just leave inpict as an indexed image and have fun dealing with carrying around colormaps if you wanted.
imshow(inpict,cmap);

请先登录,再进行评论。

更多回答(1 个)

Adam Danz
Adam Danz 2021-5-4
编辑:Adam Danz 2021-5-5
H Ghari > how can i show a matrix like this photo with black line boundaries ?
This should get you started:
rng default;
n = 100;
x = rand([1 n]);
y = rand([1 n]);
h = voronoi(x,y);
DT = delaunayTriangulation(x(:),y(:));
[V,R] = voronoiDiagram(DT);
verts = cell(size(R));
for i = 1:numel(R)
verts{i} = V(R{i}([1:end,1]),:);
end
hold on
axlims = [xlim; ylim]; % [xlim; ylim]
patchColors = hsv(numel(verts)+1);
for j = 1:numel(verts)
patch(verts{j}(:,1), verts{j}(:,2), patchColors(j,:))
end
delete(h)
set(gca,'color', patchColors(end,:)) % <-- kind of cheating
axis equal
xlim(axlims(1,:))
ylim(axlims(2,:))
Also see these two blog posts by Mike Garrity.
And the vononi2mask or the voronoizone functions on the file exchange (not tested).
  13 个评论
ali can kaya
ali can kaya 2023-10-5
编辑:Walter Roberson 2023-10-5
Hi
Do you knoW hoW can I mesh this data for abaqus?
If you have any idea it would help me alot. I tried here delanuay triangulate but did not work
th = linspace( pi/3.4, -pi/2, 100);
R = 0.25; %or whatever radius you want
for i=0:0.2:1
for j=0:0.4:1
x = R*cos(th)+i ;
y = R*sin(th)+j ;
plot (x,y)
hold on
end
end
rng default
x= rand([1 50]);
y= rand([1 50]);
voronoi(x,y)
DT = delaunayTriangulation(x(:),y(:));
[V,R] = voronoiDiagram(DT);
verts = cell(size(R));
for i = 1:numel(R)
verts{i} = V(R{i}([1:end,1]),:);
end
xlim([0 1.3])
ylim([-0.2 1])
DGM
DGM 2023-10-5
编辑:DGM 2023-10-5
I suggest you open a new question for this.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Blue 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by