MATLAB Answers

0

how compute the pixel sum for image?

Asked by houssem rouine on 11 Apr 2018
Latest activity Answered by Pawel Jastrzebski on 11 Apr 2018
Hello freinds, I am a beginner in matlab and i want know how compute the pixel sum for image

  2 Comments

Adam
on 11 Apr 2018
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(:) );
thank you so much for your helping.

Sign in to comment.

1 Answer

Answer by Pawel Jastrzebski on 11 Apr 2018

  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))

  0 Comments

Sign in to comment.