MATLAB Answers

ROI Image Processing for Edge Contrast

16 views (last 30 days)
Kevin P Meyer
Kevin P Meyer on 25 Sep 2021 at 22:58
Commented: Kevin P Meyer on 7 Oct 2021 at 18:02
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..
IM = imread('air.jpg');
IM = rgb2gray(IM);
IM = im2double(IM);
roi = drawrectangle('StripeColor','r','FaceAlpha',0.2);
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);
edge = edge+1;
hold on

Answers (1)

Image Analyst
Image Analyst on 25 Sep 2021 at 23:41
m1 = max(arr(:));
m2 = min(arr(:));
  1 Comment
Kevin P Meyer
Kevin P Meyer on 7 Oct 2021 at 18:02
Hi IA, sorry for getting back to you so late. I tried this but the same problem occured. I took a break on this code for a while but I am back to it now. Do you have any more suggestions? I am still pretty stuck, thank you!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!