ROI Image Processing for Edge Contrast

조회 수: 3 (최근 30일)
Kevin P Meyer
Kevin P Meyer 2021년 9월 25일
댓글: Kevin P Meyer 2021년 10월 7일
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

답변 (1개)

Image Analyst
Image Analyst 2021년 9월 25일
Try
m1 = max(arr(:));
m2 = min(arr(:));
  댓글 수: 1
Kevin P Meyer
Kevin P Meyer 2021년 10월 7일
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!

댓글을 달려면 로그인하십시오.

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by