ROI Image Processing for Edge Contrast

2 vues (au cours des 30 derniers jours)
Kevin P Meyer
Kevin P Meyer le 25 Sep 2021
Commenté : Kevin P Meyer le 7 Oct 2021
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

Réponses (1)

Image Analyst
Image Analyst le 25 Sep 2021
Try
m1 = max(arr(:));
m2 = min(arr(:));
  1 commentaire
Kevin P Meyer
Kevin P Meyer le 7 Oct 2021
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!

Connectez-vous pour commenter.

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by