To sum up all color channels of each pixel and divide the result by the number of channels in matlab, we can use the mean()
function after converting the image to type double
. Here's the code:
main.m301 chars16 lines
In this code, we first read the input image using the imread()
function. Then, we compute the sum of all color channels of each pixel using the sum()
function. The 3
as the second argument to sum()
is the dimension to sum over.
Next, we divide this sum by the number of channels in the image (n = size(img, 3)
). The result is a double
array, which we then round using the round()
function and convert to type uint8
using the uint8()
function.
Finally, we display the result using the imshow()
function.
gistlibby LogSnag