How to plot a subset of triangles after DelaunayTri
古いコメントを表示
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
採用された回答
その他の回答 (1 件)
Amani
2013 年 12 月 9 日
0 投票
14 件のコメント
Simon
2013 年 12 月 11 日
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
2013 年 12 月 16 日
Amani
2013 年 12 月 16 日
Simon
2013 年 12 月 16 日
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
2013 年 12 月 17 日
Simon
2013 年 12 月 17 日
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
2013 年 12 月 18 日
Simon
2013 年 12 月 18 日
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
2013 年 12 月 18 日
Simon
2013 年 12 月 18 日
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
2013 年 12 月 18 日
Amani
2013 年 12 月 19 日
Simon
2013 年 12 月 19 日
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
2013 年 12 月 23 日
カテゴリ
ヘルプ センター および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!