How to Seperate Region of Interest into 3 Segments
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello--
In my code I use binarization to crop my region of interest from a photograph to observe lightness values as shown bellow:
All I want to do is use another threshhold to seperate the the picture into 3 more segments for individual analysis. So I would want my final picture to be split up like this:
I do not care if there needs to be more figures or whatnot its just seperating this image is very important to me. Please help if you know how! I know the color values in the strip vary in intensity so I know this can be done. My code is as follows:
I0 = imread(f{3}); %f{3} is some random photo in this case
I1 = I0(:,:,3); % select 3d channel
I2 = im2bw(I1,graythresh(I1)-0.1); % binarization
figure(n);
imshow(I2)
h = msgbox('select region 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);
답변 (2개)
darova
2020년 7월 2일
Adapt this example for your needs
[x,y] = meshgrid(1:100);
I0 = (x-50).^2/4 + (y-50).^2 < 20^2; % create ellipse
[i1,j1] = find(I0,1,'first'); % firt first pixel
[i2,j2] = find(I0,1,'last'); % find last pixel
I1 = double(I0);
dx = round((j2-j1)/4); % length of region
for i = 1:4
jj = j1+((i-1)*dx:i*dx-1); % first and last columns
I1(:,jj) = I1(:,jj) *i; % label region
end
imshow(label2rgb(I1))
댓글 수: 0
Image Analyst
2020년 7월 2일
If you want equal thirds, just use regionprops() to get the bounding box and then figure out what the columns are to divide it by.
I2 = imfill(I2, 'holes');
I2 = bwareafilt(I2, 1); % Take largest blob only.
props = regionprops(I2, 'BoundingBox');
width = props.BoundingBox(3)
% Get the columns that divide the blob into 3 regions.
col1 = props.BoundingBox(1)
col2 = round(col1 + width/3);
col3 = round(col1 + 2 * width/3);
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!