필터 지우기
필터 지우기

Average value of H in HSV of a picture

조회 수: 1 (최근 30일)
Xiaochao
Xiaochao 2012년 9월 10일
I was asked to divide a jpg picture to several parts with equal area. And I need to get average value of H in HSV of the picture. I want to know how to get the average value of H.

채택된 답변

Jan
Jan 2012년 9월 10일
편집: Jan 2012년 9월 10일
Calculate the mean over 4x4 blocks:
RGB = rand(100, 200, 3);
HSV = rgb2hsv(RGB);
H = HSV(:, :, 1);
meanH = mean(H(:));
BlockH = reshape(H, 4, 25, 4, 50);
meanBlockH = reshape(sum(sum(H, 1), 3), 25, 50) / 16;
Care about the overflow, when you use UINT8 images.
  댓글 수: 3
Xiaochao
Xiaochao 2012년 9월 11일
I have a picture of 640*480 pixels. I want to divide it to 16*16 blocks and get average value H of every block. The result shoud be a 40*30 array. But I tried mean function, the result always is a 1*16 array.
Jan
Jan 2012년 9월 11일
Exactly as shown in my example:
BlockH = reshape(H, 16, 40, 16, 30);
meanBlockH = reshape(sum(sum(H, 1), 3), 40, 30) / 256;

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

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 9월 10일
  댓글 수: 1
Xiaochao
Xiaochao 2012년 9월 10일
Thank you very much, I will try this functio

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

Community Treasure Hunt

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

Start Hunting!

Translated by