Clear Filters
Clear Filters

Select particular region of image without imcrop

8 views (last 30 days)
I'm attaching a point of care test strip image link, I want to select the rectangle portion containing control and test line for processing, How to automatically select roi without imcrop?

Accepted Answer

Image Analyst
Image Analyst on 12 Mar 2015
You can use rbbox() or imrect(). Or try to find it automatically.
  2 Comments
Sagar
Sagar on 12 Mar 2015
@Image Analyst, Sir you might be having good reputation that does not mean you can answer like this. what does "Or try to find it automatically" mean?
Image Analyst
Image Analyst on 12 Mar 2015
I'm not sure what your response means - I can and did answer, and was waiting for some feedback so I don't have to describe all methods. Anyway, I'll describe them all in more detail now.
You can use indexing to get the subimage without using the imcrop() function:
subImage = fullImage(row1:row2, col1:col2, :);
but to get row1, row2, col1, and col2, you can either specify them manually by the user drawing a box, or you can try to do some image analysis to determine them. If you are happy to have the user manually specify the box, you can use rbbox, or imrect. Here is a snippet where I used it in the attached colorize_ROI_box.m demo for a gray scale image:
message = sprintf('Draw a box');
uiwait(msgbox(message));
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint'); % button down detected
finalRect = rbbox; % return figure units
point2 = get(gca,'CurrentPoint'); % button up detected
point1 = point1(1,1:2); % extract x and y
point2 = point2(1,1:2);
p1 = min(point1,point2); % calculate locations
offset = abs(point1-point2); % and dimensions
x = round([p1(1) p1(1)+offset(1) p1(1)+offset(1) p1(1) p1(1)])
y = round([p1(2) p1(2) p1(2)+offset(2) p1(2)+offset(2) p1(2)]);
hold on
axis manual
plot(x,y)
croppedImage = grayImage(y(1):y(3), x(1):x(2));
In the attached delta E demo, you'll find a way to do it with imrect():
hBox = imrect;
roiPosition = wait(hBox);
roiPosition % Echo coordinates to the command window.
If you want to do it automatically, these are the steps I'd follow
  1. extract the color channel that has the greatest contrast between the center box and the outside background region
  2. threshold it to get a binary image
  3. Clean the image by extracting just the largest blob (see function in attached demo)
  4. call imerode() to shrink the blob to get away from shadowy edge regions
  5. call bwlabel
  6. call regionprops and ask for Bounding box.
  7. Crop the image using indexing like I showed you at the beginning of this comment.
See my Image Segmentation Tutorial if you need help with regionprops or cropping. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!