how compute the pixel sum for image?

조회 수: 9 (최근 30일)
houssem rouine
houssem rouine 2018년 4월 11일
댓글: Walter Roberson 2019년 10월 28일
Hello freinds, I am a beginner in matlab and i want know how compute the pixel sum for image
  댓글 수: 2
Adam
Adam 2018년 4월 11일
What is wrong with
doc sum
?! Even as a beginner it is surely the most obvious place to look.
You do need to collapse the image to 1d though or use a double sum, e.g.
pixelSum = sum( myImage(:) );
houssem rouine
houssem rouine 2018년 4월 11일
thank you so much for your helping.

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

답변 (1개)

Pawel Jastrzebski
Pawel Jastrzebski 2018년 4월 11일
  1. Use imread - output to load the image into Matlab and store it as a matrix - it can be anything between 2d and 4D matrix
  2. Dimension 1 and 2 of the matrix are width and height of the image in pixels
% load the image into the matrix
A = imread('http://www.matlabtips.com/wp-content/uploads/2014/07/64848_wl_cc_logo_membrane_2002_wl.gif');
dims = size(A)
NoOfPixels = prod(dims)
% Note if 'dims' is bigger than 2 elements then:
% NoOfPixels = prod(dims(1:2))
  댓글 수: 2
Fhynthiazien Bobby
Fhynthiazien Bobby 2019년 10월 28일
Hi, i tried using the code and my output is as below:
dims =
531 614 3
NoOfPixels =
978102
Therefore sir, does the value 978102 represents the overall sum of pixel for the image??
Walter Roberson
Walter Roberson 2019년 10월 28일
No, in that code, NoOfPixels is the number of array elements in the image. It is not necessarily the number of pixels: the number of pixels would be dims(1)*dims(2) . The difference comes about for RGB, in which there are 3 array elements per pixel.
If you are looking for the sum of the pixels, you need to define what that means for RGB.
sum(A, [1 2]) %since R2019a

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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by