フィルターのクリア

How to calculate the intensity of every pixel in a RGB image

47 ビュー (過去 30 日間)
Avi Patani
Avi Patani 2020 年 2 月 27 日
コメント済み: DGM 2022 年 10 月 25 日
Hi,
% I am trying to calulate the intensity of every pixel in an image.
% The project I am working on, we are trying to see the blomming effect on every pixel and how it affects us.
% I am using the following code and not sure if its correct.
J = imread('Image7.png');
R = J(:,:,1);
G = J(:,:,2);
B = J(:,:,3);
% Intensity Calcultions:
I = (R(:,:)+G(:,:)+B(:,:))/3;
I3 = (R(:,:)+G(:,:)+B(:,:));
%I2= I/2;
histogram(I3,25)
xlabel('Intensity')
ylabel('# of pixels')
Me = mean(I(:));
histogram(Me,25)
csvwrite('Intensity7.csv',I3);

採用された回答

Guillaume
Guillaume 2020 年 2 月 27 日
編集済み: Guillaume 2020 年 2 月 27 日
For a start, you'll have to define what the intensity of a colour pixel is. According to the code you wrote, it looks like you define intensity as the sum of red, green and blue which is not what most people would call intensity (no idea what you'd call that sum it's fairly meaningless). Most people would probably define intensity as the perceived luminance but there are other definition you could use.
Secondly, most likely your image is of class uint8. The maximum value of uint8 is 255. You can't add uint8 values and expect the result to make sense. If the sum is greater than 255, you'll get 255:
>> uint8(200) + uint8(150) %does not sum to 300
ans =
uint8
255
Thirdly note that R(:, :) is just a complicated way of writing just R. Same for the other channels. I'm not sure what you think R(:, :) would do differently.
Anyway, if you want to calculate the mean of the red, green and blue channel, which is also not something people would call intensity, it's simply:
%J a RGB image of any class
I = mean(J, 3); %mean across the colour planes. Will work properly unlike your (R+G+B)/3
  2 件のコメント
Avi Patani
Avi Patani 2020 年 3 月 4 日
That works for me, Thank you so much for your help and time
DGM
DGM 2022 年 10 月 25 日
Not that it really matters now, but the mean of the channels is "intensity" (I) within the context of HSI. For some reason it seems some courses focus on using HSI for image processing.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOctave についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by