How to plot a subset of triangles after DelaunayTri
Mostra commenti meno recenti
I have computed a Delaunay triangulation using DelaunayTri(). Then I extracted big triangles based on a threshold, how can I reconstruct these triangles and plot it in a figure ?
thanks
Risposta accettata
Più risposte (1)
Amani
il 9 Dic 2013
0 voti
14 Commenti
Simon
il 11 Dic 2013
The above code can be used as well:
% find connected triangles to ID
[ind, ~] = ind2sub(size(TRI), find(TRI==ID));
% connected vertices
vert = setdiff(unique(TRI(ind,:)), 1)
% y-distance
X(ID, 2) - X(vert, 2)
Amani
il 16 Dic 2013
Amani
il 16 Dic 2013
Simon
il 16 Dic 2013
Almost the same:
- compute the y-distance of all vertices to the given one
- finding all distances below threshold gives you vertex IDs
- find those vertex IDs in triangulation
Amani
il 17 Dic 2013
Simon
il 17 Dic 2013
Sorry, but I don't understand what you're doing. Where do the triangles come from? What is the source for triangulation? How does the "original text" look like?
Amani
il 18 Dic 2013
Simon
il 18 Dic 2013
Hi!
Now I see what you are doing ;-)
What is the reason that you are using triangulations for this? I did something similar a while ago (not for text, but other images). I found the script and adapted it for your image. Try it and see if it is useful for you.
% file with handwritten text
filename = 'ARA_D01_W0001.jpg';
% read in
A = imread(filename);
% and show
figure(1); cla;
image(A)
% make combined color value
Amode = double(A(:,:,1)) * 2^16 + double(A(:,:,2)) * 2^8 + double(A(:,:,3));
% color most often used -> background
BackColor = mode(Amode(:));
% find RGBs of background
ind = find(Amode == BackColor, 1);
[x,y] = ind2sub(size(Amode), ind);
% background RGB
BackRGB = squeeze(A(x, y, :));
% threshold for background detection
BackThreshold = 20;
% image mask, everything that is background is set to true
ImageMask = ...
(A(:, :, 1) > (BackRGB(1) - BackThreshold)) & ...
(A(:, :, 1) < (BackRGB(1) + BackThreshold)) & ...
(A(:, :, 2) > (BackRGB(2) - BackThreshold)) & ...
(A(:, :, 2) < (BackRGB(2) + BackThreshold)) & ...
(A(:, :, 3) > (BackRGB(3) - BackThreshold)) & ...
(A(:, :, 3) < (BackRGB(3) + BackThreshold));
% threshold of line/paragraph detection (number of background pixel in y-direction)
BackYThreshold = 1;
% image mask for background lines in image
LineMask = false(size(ImageMask));
for y = (1+BackYThreshold):(size(A, 1)-BackYThreshold)
for x = 1:size(A, 2)
%R check y-range
if ImageMask(y, x)
if all(ImageMask((y-BackYThreshold):(y+BackYThreshold), x))
LineMask(y, x) = true;
end
end
end
end
% find lines with only background
LineMask = all(LineMask, 2);
figure(2); cla;
image(LineMask*255);
Amani
il 18 Dic 2013
Simon
il 18 Dic 2013
Then you have a grayscale image, that only has 1 as
size(A, 3)
in contrast to a RGB image with 3. So check "size(A, 3)" and do
if size(A, 3) == 1
Amode = double(A);
elseif size(A, 3) == 3
Amode = double(A(:,:,1)) * 2^16 + double(A(:,:,2)) * 2^8 + double(A(:,:,3));
endif
Amani
il 18 Dic 2013
Amani
il 19 Dic 2013
Simon
il 19 Dic 2013
I used gimp for conversion. But I think you should not divide by 255. Images in matlab are uint8 with values between 0 and 255, in contrast to color values for e.g plotting with values between 0 and 1.
Amani
il 23 Dic 2013
Categorie
Scopri di più su Surface and Mesh Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!