How to plot a subset of triangles after DelaunayTri
3 次查看(过去 30 天)
显示 更早的评论
Amani
2013-12-9
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
采纳的回答
Simon
2013-12-9
Hi!
If you have a triangulation you can of course plot specific triangles (if you know them) with
TRI = dt.Triangulation;
X = dt.X;
ind = [1,2,3,4,5];
triplot(TRI(ind, :), X(:, 1), X(:, 2));
5 个评论
Amani
2013-12-11
what about if I have the IDs of Bounding Vertices, how can I plot the triangles ? in other words, how can I get the ind of the IDs of bounding vertices ?
Simon
2013-12-11
Just find all triangles in TRI with the specified vertex IDs:
[ind, ~] = ind2sub(size(TRI), find(TRI==ID))
Simon
2013-12-12
I used the code:
x = rand(20,1);
y = rand(20,1);
dt = DelaunayTri(x,y);
figure(1)
triplot(dt);
ID = 1;
TRI = dt.Triangulation;
X = dt.X;
[ind, ~] = ind2sub(size(TRI), find(TRI==ID));
figure(2)
triplot(TRI(ind, :), X(:, 1), X(:, 2));
Works without problems.
更多回答(1 个)
Amani
2013-12-9
how can I calculate the distance between two connected vertices (only Y coordinate) TRI = dt.Trangulation for q=1:size(dt,1) for u=1:size(dt,1) j = isConnected(k,q,u); if (j == true) % retrive q and u (y coordinate) and calculate the distance between them end
end
thanks
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
thank you very much
what about if the y-distance < Threshold and I need to find only the connected vertices (not triangles) with ydistance below the threshold ...how can I retrieve them ?
thanks
Amani
2013-12-16
I'm trying to do the reverse of this code 1- find vertices (edge) with distance less than a threshold 2- find their triangles
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
thank you very much actually what I'm trying to do is to find the text lines in a handwritten documents so after creating triangles using triangulation I want to divide the text into title or subtitles and paragraphs based on tracing the edges (or triangles) horizontally to identify those regions you can find the generated triangles based on the centroid of connected components here https://lh6.googleusercontent.com/-Y-N-05Y5hx4/Uq_xp9w98hI/AAAAAAAAAAc/2GNXwURh5pY/w560-h420-no/Triangles.jpg what do you thing the best way to do so? really appreciate you help
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
the source of triangulation is the centers of connected component of the handwritten text, and I want to divide the text into regions: title, subtitle and paragraphs you can find the original documents here https://lh6.googleusercontent.com/-RjnIpj7Qn9Y/UrE0o_8B24I/AAAAAAAAABw/4boaEyJ1FMY/w426-h554/ARA_D01_W0001.tif
thank you
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
thank you gain and again :) actually I'm modifying someone else code and he is using triangulation, he got a very good result with long text line but not with short ones I got this error when I run your code
Index exceeds matrix dimensions.
Error in simon (line 9)
Amode = double(A(:,:,1)) * 2^16 + double(A(:,:,2)) * 2^8 + double(A(:,:,3));
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
ok , then should I change the ImageMask ?
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));
Amani
2013-12-19
when I modified the code to
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));
end
and run it I got this error
Index exceeds matrix dimensions.
Error in simon (line 84) ImageMask = ...
I converted the grayscale image into RGB using this code
[m n]=size(A);
rgb=zeros(m,n,3);
rgb(:,:,1)=A;
rgb(:,:,2)=rgb(:,:,1);
rgb(:,:,3)=rgb(:,:,1);
A=rgb/255;
it works without error but image (A) was all zeros and (ImageMask) was all ones
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
I remove \255 but still did not work .. is there any other way for conversion to rgb?
thanks
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Filtering and Enhancement 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)