Can anyone explain me these lines?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
1 개 추천
Iam new to image processing. Please explain these lines. what does BoundingBox(2) and BoundingBox(4) mean? Iam trying to form bounding box around brain tumour. How can these lines help me?
starti=round(STATS.BoundingBox(2));
endi=round(STATS.BoundingBox(2) + STATS.BoundingBox(4));
채택된 답변
Walter Roberson
2016년 3월 6일
Bounding boxes extracted by regionprops are vectors of 4 items per region. The first item in the vector is the x coordinate of the left of the box. The second item in the vector is the y coordinate of the bottom of the box. The third item in the vector is the width of the box. The fourth item in the vector is the height of the box.
The second item plus the fourth item is thus the row (y) of the bottom of the box, plus the height of the box. The total will be the row (y) that is just past the top of the box.
The code is likely in error. Usually what is desired is to find the row of the bottom of the box and the row of the top of the box so that you can index. That would be
starti = STATS.BoundingBox(2);
endi = starti + STATS.BoundingBox(4) - 1;
and then you would be able to do
TheImageArray(starti : endi, ....)
Remember, that if something starts at (say) row 3 and is (say) 5 high, then that would be rows 3, 4, 5, 6, 7 -- 5 rows including the starting row. The calculation in the code you were looking at would be endi = 3 + 5 = 8, but row 8 is past the top of the box.
People make this mistake with bounding boxes a lot. It is often not noticed, and often does not affect much. But if the bounding box happens to end at the edge of the image, then that "one too far" would try to index past the end of the array.
"There are 2 hard problems in computer science: caching, naming, and off-by-1 errors"
댓글 수: 10
Thank you so much. It is really helpful. I have some more doubts. I hope you respond to those questions also. Once again thank you so much.
I is my input image
h = size(I,1);
midx = round(STATS.Centroid(1));
plot([midx,midx],[h,1],'linewidth',1);
Please explain me the parameters inside plot() function. I don't understand what [h 1] represents. Thank you
h would be the number of rows in "I", which would be the height of "I".
midx is going to be the x coordinate of the single centroid (or an error if there are multiple objects in the image).
What the plot doing is drawing a vertical line at the x coordinate of the centroid -- a line between y = the height and y = 1
mounika siripurapu
2016년 3월 6일
편집: Walter Roberson
2016년 3월 6일
Thank you so much. I already asked about bounding box. Please explain me these lines too.
startj=1;
endj=floor(min(STATS.BoundingBox(1) + STATS.BoundingBox(3)-midx+1, midx- STATS.BoundingBox(1)+1));
The first part of the min() is the distance between the centroid and the right edge. The second part of the min() is the distance between the centroid and the left edge. The min() is therefore figuring out the distance of the closer edge to the centroid. I am not sure why you would want to do that.
mounika siripurapu
2016년 3월 6일
편집: mounika siripurapu
2016년 3월 6일
Thank you. I wanted to perform horizontal scan(left to right). For that purpose, starting and ending positions are determined by above those two steps.
what does zeros(endi-starti+1,1); returns?
Thank you.
zeros(K,1) for any integer value K, returns a column vector of zeros which is K long. For example zeros(5,1) would be [0; 0; 0; 0; 0] which is
0
0
0
0
0
Thank you so much
A slight correction. The bounding box does not actually lie ON the left most and top most line of pixels, it lies in between the lines of pixels. Try it with a small example and you'll see.
b = false(4,7);
b(2:3, 4:6) = true;
m = regionprops(logical(b), 'BoundingBox')
m.BoundingBox
startRow = ceil(m.BoundingBox(2))
endRow = startRow + m.BoundingBox(4) - 1
b =
0 0 0 0 0 0 0
0 0 0 1 1 1 0
0 0 0 1 1 1 0
0 0 0 0 0 0 0
m =
BoundingBox: [3.5 1.5 3 2]
ans =
3.5 1.5 3 2
2
endRow =
3
The first element is 0.5 pixels to the left of the first column with something in it, and the top row is half a pixel above the first row with something in it. This is so that the bounding box actually contains the image, whereas if it were right on top of it, it could be somewhat ambiguous whether those columns and rows were "inside" the box or not.
The width and height are correct using pixel center-to-pixel center paradigm. So if you want to crop with indexing you'd have to do
startRow = ceil(m.BoundingBox(2))
endRow = startRow + m.BoundingBox(4) - 1
startCol = ceil(m.BoundingBox(1))
endCol = startCol + m.BoundingBox(3) - 1
startRow =
2
endRow =
3
startCol =
4
endCol =
6
Just as you expect and see in the "b" image above.
As far as cropping goes, note the different ways imcrop() and indexing operate.
croppedImage = imcrop(b, m.BoundingBox)
croppedImage2 = b(startRow:endRow, startCol:endCol)
croppedImage =
1 1 1 0
1 1 1 0
0 0 0 0
croppedImage2 =
1 1 1
1 1 1
Thank you
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
제품
참고 항목
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)
