필터 지우기
필터 지우기

How to compute the mean of two disjoint region ?

조회 수: 1 (최근 30일)
Makrim
Makrim 2015년 5월 1일
댓글: Image Analyst 2015년 5월 2일
Suppose I have to fragment of an image J : J_out_1 et J_out_2.
J_out_1 = J(1:h,startj:i);
J_out_2 = J(1:h,k:endj);
I would like to compute the mean of the union of those two regions , is it possible ?
m_out = mean2(J_out_1 union J_out_2);
Thank you in advance

채택된 답변

Guillaume
Guillaume 2015년 5월 1일
편집: Guillaume 2015년 5월 1일
m_out = mean([J_out_1(:); J_out_2(:)])
would be one way to do it assuming the image has only one colour channel. If they are RGB images:
m_out = mean([reshape(J_out_1, 1, [], 3), reshape(J_out_2, 1, [], 3)])
Note that if the two regions are the same size, you could just concatenate them without any reshaping (by colon or reshape).
  댓글 수: 1
Makrim
Makrim 2015년 5월 2일
excellent, that's what I am looking for.finally I have done it as follow :
m_out = mean2([J_out_1 , J_out_2])

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

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 5월 1일
Why not just take the weighted mean of the two?
numerator = numel(J_out_1) * mean2(J_out_1) + numel(J_out_2) * mean2(J_out_2)
denominator = numel(J_out_1) + numel(J_out_2)
m_out = numerator / denominator
If you want, you could make a binary image and use that as a mask to extract all the pixels in just the two regions:
binaryImage = false(size(J));
binaryImage(1:h,startj:i) = true;
binaryImage(1:h,k:endj) = true;
m_out = mean(J(binaryImage))
  댓글 수: 2
Makrim
Makrim 2015년 5월 2일
that's another way, Yes , thank you. by the way the idea of using Logical is also brilliant.
Image Analyst
Image Analyst 2015년 5월 2일
You're welcome. Those ways will also work even if the two subimages don't have the same number of rows. So "h" could be different for each image and they would still work.

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

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by