Select particular region of image without imcrop
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sagar
el 12 de Mzo. de 2015
Comentada: Image Analyst
el 12 de Mzo. de 2015
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?
0 comentarios
Respuesta aceptada
Image Analyst
el 12 de Mzo. de 2015
You can use rbbox() or imrect(). Or try to find it automatically.
2 comentarios
Image Analyst
el 12 de Mzo. de 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
- extract the color channel that has the greatest contrast between the center box and the outside background region
- threshold it to get a binary image
- Clean the image by extracting just the largest blob (see function in attached demo)
- call imerode() to shrink the blob to get away from shadowy edge regions
- call bwlabel
- call regionprops and ask for Bounding box.
- 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
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!