HSV Averages and SD for Image Processing Toolbox

조회 수: 19 (최근 30일)
Jacob Siahaan
Jacob Siahaan 2020년 4월 30일
댓글: Jacob Siahaan 2020년 4월 30일
I am new to Matlab, it is only my first week. I am trying to calculate the average hue across all image pixels along with the standard deviation. Same applies to saturation and value.
My code is:
rgbImage = imread('001.jpg');
hsv = rgb2hsv(rgbImage);
h = hsv(:, :, 1); % Hue image.
s = hsv(:, :, 2); % Saturation image.
v = hsv(:, :, 3); % Value (intensity) image.
meanh = mean(h);
display(meanh)
My output shows columns, but I am seeking the average across all image pixels and to my understanding it seems like the table (for mean) shows average hue per pixel.

채택된 답변

Guillaume
Guillaume 2020년 4월 30일
편집: Guillaume 2020년 4월 30일
mean like many functions in matlab operates along the first non-scalar dimension of a matrix. Your h is a 2D matrix, so the first non-scalar dimension is the rows and mean gives you the average across the rows (hence the average of each column).
If you're using a reasonably modern version of matlab (2018b or later) you can tell mean to operate across all the dimensions at once:
meanh = mean(h, 'all');
In older versions, you can either call mean twice:
meanh = mean(mean(h)); %first get the mean across the rows, then across the columns
but be careful that it doesn't work for non-linear functions such as std. Instead you can reshape your matrix so it has only one dimension:
meanh = mean(h(:)); %reshape into a column, then take the mean
or use the mean2 function which gives you the mean of all pixels of a 2D image:
meanh = mean2(h);
I recommend the first ('all' option) or 3rd option ( use (:)) for older versions.
  댓글 수: 1
Jacob Siahaan
Jacob Siahaan 2020년 4월 30일
Thank you so much sir, the codes worked for me.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by