MATLAB Answers

How to Seperate Region of Interest into 3 Segments

7 views (last 30 days)
Brian Peoples
Brian Peoples on 1 Jul 2020
Commented: Brian Peoples on 6 Jul 2020
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
h = msgbox('select region of interest');
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


Brian Peoples
Brian Peoples on 1 Jul 2020
If there is any questions regarding this please let me know I think I explained the issue fairly well
Brian Peoples
Brian Peoples on 1 Jul 2020
and if you notice in the binarized isolated image we can see a series of lightness values due to glare, much higher values in the middle, and less on the sides. That is how I am looking to seperate

Sign in to comment.

Answers (2)

darova on 2 Jul 2020
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


Sign in to comment.

Image Analyst
Image Analyst on 2 Jul 2020
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);

Translated by