I am doing my project in medical imaging. I am getting "index exceeds matrix dimensions" while trying to segment the lungs. please help me

2 views (last 30 days)
I = im2double(imread('onee.png'));
I=I(:,:,1);
cropped = I(50:430,8:500); %%Crop region of interest
thresholded = cropped < 0.35; %%Threshold to isolate lungs
clearThresh = imclearborder(thresholded); %%Remove border artifacts in image
Liver = bwareaopen(clearThresh,100); %%Remove objects less than 100 pixels
Liver1 = imfill(Liver,'hole'); % fill in the vessels inside the lungs
imshow(Liver1.*cropped)
  2 Comments
Stephen23
Stephen23 on 2 Sep 2014
Edited: Stephen23 on 2 Sep 2014
Please edit your question by formatting your code to be more readable: this will encourage people to read and understand what you are trying to do. You will find some buttons immediately above the text field, allowing you to add some basic formatting. Use the "{} Code" button to format any code, keeping the code tidy, eg one line per line of code. Pay attention to the "Preview" pane underneath too!
Some explanation of what you understand, what you are trying and what you expect would be useful information for potential helpers here...
Ank
Ank on 2 Sep 2014
Edited: Walter Roberson on 17 Nov 2015
I(50:430,8:500)
may be this line.
what is the size of the image is it more than 430x500? If no then you are accessing values outside the matrix hence the error.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 2 Sep 2014
Put this line right before your crop:
[rows, columns] = size(I)
What do you see? Are there at least 430 rows and 500 columns? No, there are not.

Categories

Find more on Medical Physics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!