MATLAB Answers

Image Intensity

790 views (last 30 days)
M@lik Ali
M@lik Ali on 4 Jun 2012
Commented: Walter Roberson on 10 Sep 2020 at 20:27
Hi all, Can any one tel me the command in matlab to calculate the intensity of image.

  2 Comments

Jean
Jean on 5 Jul 2013
Does anyone further know how to do this for a specific area of pixels? For example, image(100:1:200,100:1:200) for a 100 by 100 pixel area, and get the intensity in this area as an average?
Image Analyst
Image Analyst on 5 Jul 2013
meanGrayLevel = mean2(yourImage(100:200,100:200));
Don't use "image" as the name of your variable since it's a function.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 4 Jun 2012
The mean of a particular pixel is just simply the pixel value, since there is only one sample - nothing really to take the mean of:
intensityValue = grayImage(100, 230);
meanIntensityValue = mean(grayImage(100, 230));
Here, of course meanIntensityValue will equal intensityValue.
To get the mean of all the pixel values in the entire image, you can do any of these:
meanIntensityValue = mean2(grayImage);
meanIntensityValue = mean(grayImage(:));
meanIntensityValue = mean(mean(grayImage));

  10 Comments

Show 7 older comments
Samantha Villanueva
Samantha Villanueva on 9 Sep 2020 at 13:45
hello can I use this to a colored image?
Image Analyst
Image Analyst on 10 Sep 2020 at 16:36
You would have to do it on every color channel independently:
[r, g, b] = imsplit(rgbImage);
meanRed = mean2(r);
meanGreen = mean2(g);
meanBlue = mean2(b);
Walter Roberson
Walter Roberson on 10 Sep 2020 at 20:27
As the question is about mean intensity, then which definition of "intensity" do you want to use for your RGB image?

Sign in to comment.

More Answers (4)

Adina Stoica
Adina Stoica on 4 Jun 2012
Well, the intensity of the image is the average of the intensities of all pixels in an image (unless you're doing anything more specific than that). So if you do
mean(imagefile(:))
you should get the intensity of the image.

  1 Comment

M@lik Ali
M@lik Ali on 4 Jun 2012
Adina thanks for your response,
But actually i want to calculate the intensity value of all elements of the images.
someone told me like
intensityValue = grayImage(100, 230);
But in i have to calculate the intensity value of each pixel or total image, i think i can do it by calculating the intensity of each pixel and then add it but i am not sure.
Kindly help me about it..

Sign in to comment.


Saranya
Saranya on 30 Jan 2014
hi image analyst i want to measure the intensity profile for gray scale image.. can you help me..?

  18 Comments

Walter Roberson
Walter Roberson on 20 Mar 2017
It looks like you just have to pick either a representative pixel or a representative level and call graydiffweight() passing in the data and the location or level.
Rasika Devi
Rasika Devi on 21 Mar 2017
Thank you so much sir.. One more thing from that weight value,how do i perform the image segmentation by using any algorithm? kindly help me...
Walter Roberson
Walter Roberson on 21 Mar 2017
I suggest you look in the File Exchange, for Image Analyst's Image Segmentation Tutorial

Sign in to comment.


Syakira Akmal
Syakira Akmal on 3 Apr 2017
May I know how to convert intensity of image inform of histogram?

  1 Comment

Image Analyst
Image Analyst on 3 Apr 2017
[counts, grayLevels] = imhist(grayImage);

Sign in to comment.


swetha Derangula
swetha Derangula on 5 Aug 2017
Edited: Walter Roberson on 5 Aug 2017
Is this code correct for entire image intensity? I didn't get any intensity value
clear all;
close all;
o=imread('450.jpg');
i=rgb2gray(o);
imshow(i)
intensityValue = i(100, 230);
meanIntensityValue = mean(mean(i));
please suggets me

  2 Comments

Walter Roberson
Walter Roberson on 5 Aug 2017
No code that contains "clear all" can be correct.
Your line
intensityValue = i(100, 230);
extracts one particular pixel's intensity, and only that one pixel. However,
meanIntensityValue = mean(mean(i));
should be fine for taking the mean intensity of the entire image.
Image Analyst
Image Analyst on 6 Aug 2017
You could also use mean2().

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by