matrix show , grain boundaries

6 views (last 30 days)
HG
HG on 4 May 2021
Edited: Walter Roberson on 5 Oct 2023
how can i show a matrix like this photo with black line boundaries ?
  2 Comments
KSSV
KSSV on 4 May 2021
What data you have? You need to have a look on voronoi.
DGM
DGM on 4 May 2021
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().

Sign in to comment.

Accepted Answer

DGM
DGM on 5 May 2021
Edited: DGM on 6 May 2021
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 Comments
HG
HG on 11 Jun 2021
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 on 11 Jun 2021
Edited: DGM on 11 Jun 2021
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);

Sign in to comment.

More Answers (1)

Adam Danz
Adam Danz on 4 May 2021
Edited: Adam Danz on 5 May 2021
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 Comments
ali can kaya
ali can kaya on 5 Oct 2023
Edited: Walter Roberson on 5 Oct 2023
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 on 5 Oct 2023
Edited: DGM on 5 Oct 2023
I suggest you open a new question for this.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!