ROI Image Processing for Edge Contrast
3 views (last 30 days)
Show older comments
Hello, I am working on code that inputs an image of an object, and finds the edge contrast around that object. It does this by creating a rectangular ROI on the image, the user then moves the roi to different edge positions around the object, and takes the maximum and minimum values in the rectangular roi, finally getting the contrast from the difference between the max and min. I am wanting to plot the contrast for each position that the roi has moved to using a scatter plot. However, when I do this it creates 8 data points instead of just 1 data point, and I am not sure why. Could I get some help please? Thank you!
The picture on the bottom is an example of this. I moved the ROI to 3 different positions on the edge of my object. It created 3 different contrast values, but 8 different values for my region number. I think it is somewhere in my for loop or how I am scatter plotting..
clear
clc
IM = imread('air.jpg');
IM = rgb2gray(IM);
IM = im2double(IM);
imshow(IM)
roi = drawrectangle('StripeColor','r','FaceAlpha',0.2);
%addlistener(roi,'MovingROI',@allevents);
addlistener(roi,'ROIMoved',@allevents);
edge = 1;
function allevents(src,evt)
IM = imread('air.jpg');
IM = rgb2gray(IM);
IM = im2double(IM);
edge = 1;
for evname = 'ROIMoved'
h = evt.CurrentPosition;
h(1,1:2) = floor(h(1,1:2));
h(1,3:4) = ceil(h(1,3:4));
arr = IM(h(1,2):h(1,2)+h(1,4),h(1,1):h(1,1)+h(1,3));
m1 = max(arr,[],'all');
m2 = min(arr,[],'all');
contrast = abs(m1-m2);
figure(2)
scatter(edge,contrast);
edge = edge+1;
hold on
end
end
0 Comments
Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!