# How to extract the main square, image window of the ultrasound image?

조회 수: 3 (최근 30일)
Stelios Fanourakis 2019년 9월 27일
Hi
I need some help.
How do I extract/crop the main square of the ultrasound image. The image window that shows the valuable information and discard all the rest black and annotations.
Looking forward to your valuable help
Thanks

댓글을 달려면 로그인하십시오.

### 채택된 답변

Ok, the issue here is the colour maps and the conversion of uint8 to double. If you convert to double the colours are always between 0 and 1, so you would need to divide by the maximum value (in this case 255)
imagesc(double(A6__14_9N_).*(repmat(1-(background),[1 1 3]))/255)
OR you can convert to uint8 the background:
imagesc(A6__14_9N_.*(repmat(1-uint8(background),[1 1 3])))
Both should work.
##### 댓글 수: 2없음 표시없음 숨기기
Stelios Fanourakis 2019년 9월 27일
Yes they work. Thank you very much. And how do I remove the black background and keep only the gray square?
Ok, that is a bit different. You basically need to find the limits of rows and columns. Find the complement of the background
(1-background)
and sum over the columns and rows
sum( ,1)
sum( ,2)
That would generate 1D vectors where the foreground exist. The use the function "find" and select the first non-zero element (that will give you the first row/column) and the last (final row/column) and with that you can crop into a new matrix.

댓글을 달려면 로그인하십시오.

### 추가 답변 (2개)

Hard to answer without knowing your data. Post a sample and we can try.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Stelios Fanourakis 2019년 9월 27일
See attached image. Thanks

댓글을 달려면 로그인하십시오.

*IF* all the images look like this, it is rather easy, EXCEPT for the fact that the bottom edge of the ultrasound is not very well defined.
The key is to find the background to determine the foreground, The background is black, so take only one channel (the image is RGB), compare against zero and that would give the background but with the annotations and bits you want to remove, so close the image with imclose with a structural element sufficiently large to cover those elements:
background =(imclose(A6__14_9N_(:,:,1)==0,ones(25)));
Then, you only need to take the complement and recover the ultrasound part
imagesc(A6__14_9N_.*(repmat(1-background,[1 1 3])))
If you compare with the original, it seems that the job is done.
##### 댓글 수: 5이전 댓글 3개 표시이전 댓글 3개 숨기기
Stelios Fanourakis 2019년 9월 27일
I think that when I convert it to double it gets black and white.
Stelios Fanourakis 2019년 9월 27일
Did you convert it from .bmp to other format?

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Ultrasound Imaging에 대해 자세히 알아보기

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by