이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to plot a subset of triangles after DelaunayTri
조회 수: 4 (최근 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 (한국어)