Filter löschen
Filter löschen

How can I get the mean of my rgb2gray image and show the new image?

16 Ansichten (letzte 30 Tage)
Rebecca Navarro
Rebecca Navarro am 30 Sep. 2015
Kommentiert: Walter Roberson am 22 Aug. 2024 um 4:43
so far, i have ....
RGB = imread('project1.png');
A = imresize(RGB, .25 );
figure(1)
imshow(A)
%%gray scale
I = rgb2gray(RGB);
B = imresize(I, .25);
figure(2)
imshow(B)
%%mean color
m = mean(B(:)); % how do i get the mean of the gray image and then show it
figure(3)
imshow(m)

Antworten (1)

Jatin Singh
Jatin Singh am 22 Aug. 2024 um 3:49
Hi Rebecca,
As per my understanding you are trying to display an image with the mean value of the gray image.
To do that you have to display an image where each pixel has same value equal to the mean. The “imshow” function expects an image matrix, but the code is providing a scalar value equal to the mean.
Here is something you can do:
%mean color
m = mean(B(:));
%creating an image array of pixel value equal to mean
meanImage = uint8(m * ones(size(B)));
figure(3)
imshow(meanImage)
Note: This is the code that does what you want but using this will give all pixels the same value.
Kindly refer this documentation about what “uint8” does:
Hope this helps!
  1 Kommentar
Walter Roberson
Walter Roberson am 22 Aug. 2024 um 4:43
Note that there are multiple ways of constructing the mean image, including
meanImage = repmat(uint8(m), size(B));
%or
meanImage = uint8(m) + zeros(size(B), 'uint8');
%or
meanImage = uint8(m) .* ones(size(B), 'uint8');

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by