How to Threshold Crop an Image for analysis

Basically all I want to do is perform a lighting analysis on the hair itself in the border i set for it (blue tape). Is there a way I can crop this using some sort of color threshhold? the picture setup should be consistant everytime (i dont want to have to bother w imcrop(). Here is the image:

 Accepted Answer

Maybe simple binarization?
I0 = imread('image.jpeg');
I1 = I0(:,:,3);
I2 = im2bw(I1,graythresh(I1)-0.1);
imshowpair(I0,I2,'montage')

5 Comments

that seems like it would work, but what would the next step be towards cropping only the hair segment after binarization, then converting it back to rgb. If you can provide this (and I appreciate your earlier response), I will accept the answer
can you select the region manually?
I0 = imread('image.jpeg');
I1 = I0(:,:,3); % select 3d channel
I2 = im2bw(I1,graythresh(I1)-0.1); % binarization
imshow(I2)
h = msgbox('select regio of interest');
uiwait(h)
p = ginput(1); % pick point
I3 = bwselect(~I2,p(1),p(2)); % select region of interest
I4 = cat(3,I3,I3,I3);
I5 = uint8(I4).*I0; % crop rgb image
imshow(I5)
That works perfect! Now since I want to calculate average lightness of the cropped region, would the black background be used in this calculation (I'm assuming so), but I would like to remove this segment of the picture if it is possible
I understand this would probably involve reshaping the matrix to a certain extent
nvm i figured it out

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!