matrix show , grain boundaries
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
how can i show a matrix like this photo with black line boundaries ?
2 Kommentare
DGM
am 4 Mai 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().
Akzeptierte Antwort
DGM
am 5 Mai 2021
Bearbeitet: DGM
am 6 Mai 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 Kommentare
DGM
am 11 Jun. 2021
Bearbeitet: DGM
am 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);
Weitere Antworten (1)
Adam Danz
am 4 Mai 2021
Bearbeitet: Adam Danz
am 5 Mai 2021
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.
13 Kommentare
ali can kaya
am 5 Okt. 2023
Bearbeitet: Walter Roberson
am 5 Okt. 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])
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!