How to Extract part of Image inside specified boundary in MATLAB
Asked Answered
F

2

8

I am new to MATLAB, i wanted to know that can i extract a part of image from inside of a specified boundary,based on distinguishing color(red boundary in my case),The function,first traces the boundary of the image,then it extracts that part of image which is inside that particular boundary. I have my image(image of human head) attached, i wanted to extract the brain part from the head, other part of image should be ignored. I tried to find edges,using the following code(it shows 1's for boundaries, and 0 for no boundary),but it showed only 0's.

Any help will be greatly appreciated.

P.S. image attached shows original image and image with boundary....the code will be working on the one with boundary and will extract the part of image lying inside that boundary.

Below is the code i tried:

BW = edge(x)

BW = edge(x,'sobel')
BW = edge(x,'sobel',thresh)
BW = edge(x,'sobel',thresh,direction)
[BW,thresh] = edge(x,'sobel',...)

BW = edge(x,'prewitt')
BW = edge(x,'prewitt',thresh)
BW = edge(x,'prewitt',thresh,direction)
[BW,thresh] = edge(x,'prewitt',...)

BW = edge(x,'roberts')
BW = edge(x,'roberts',thresh)
[BW,thresh] = edge(x,'roberts',...)

BW = edge(x,'log')
BW = edge(x,'log',thresh)
BW = edge(x,'log',thresh,sigma)
[BW,threshold] = edge(x,'log',...)

BW = edge(x,'zerocross',thresh,h)
[BW,thresh] = edge(x,'zerocross',...)

BW = edge(x,'canny')
BW = edge(x,'canny',thresh)
BW = edge(x,'canny',thresh,sigma)
[BW,threshold] = edge(x,'canny',...)

enter image description here

Flyfish answered 15/7, 2011 at 7:14 Comment(0)
V
4

since you have presented your problem domain to be CT-images. I have a good suggestion for you to extract the region of the brain tissues. There is a good assumption you can make.

A good assumption: The brain region has no bones(normal cases) other than the cranium, and, based on some properties of CTs, you can easily extract(or remove) the bone(the cranium in this case) by looking up the Hounsfield Scale (http://en.wikipedia.org/wiki/Hounsfield_scale)

0) To get the correct housefield units, you need three elements i) original pixel value ii) rescale slope iii) rescale intercept (all three can be located in the original dicom header and HU can the be computed based on our high school math knowledge: y=mx+b, since you have the intercept, the slope and the input value).

1) Once you know where the bone is, you just need to subtract your image to get anything bounded by the cranium.

2) And upon looking at your matlab codes, im sure you can perform step 1) to segment the right regoin from the leftovers.

Vincent answered 15/7, 2011 at 8:55 Comment(3)
your answer is very good and reasonable, i will try that. (since im new to matlab,if i get any error, i will post it here)Flyfish
can i also use imcrop() for cropping the brain part? , i have tried it, but it only crops in square, is there any way to crop oval?Flyfish
@Flyfish sorry just saw your comment, you want a perfect oval or irregular shape like the gray/white matter?Vincent
A
3

Just for the record. Mathematica code:

enter image description here

Edit

If you want only to extract the brain without tracing the outline, it is actually easier:

enter image description here

Alysa answered 16/7, 2011 at 3:37 Comment(6)
thanks :-) . will this code extract the brain part within red outline? or will it just detect edges of brain.?Flyfish
Very nice, i will try this in Mathematica too. thanks again :-)Flyfish
can i also use imcrop() for cropping the brain part? , i have tried it, but it only crops in square, is there any way to crop oval?Flyfish
@Rizwan Yes, you should generate a mask and then use ImageMultiply (but you have to know in advance where your target area is located.Alysa
@ belisarius,I have tried the mathematica code but cannot seem to impoert the image, i used this command, i = Import ["C:\\Documents and Settings\\Rizwan\\Desktop\\IM14.jpg"]; but it is giving this error, Syntax::bktmop: Expression "i=Import[C:\Documents and S[Ellipsis] n\Desktop\IM14.jpg]; <<13>>[<<1>>)" has no opening "(". Syntax::sntxi: "\!(* StyleBox[\"\"\", \"MT\"])Incomplete expression; more input is needed , how can i fix it.Flyfish
@Rizwan Look at the first line in my code. You can just copy and paste the image to a variable in Mma. Your code is also right, try to write it in a clean notebook, I think the error comes from another line or from hidden chars in the folder nameAlysa

© 2022 - 2024 — McMap. All rights reserved.