フィルターのクリア

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

16 ビュー (過去 30 日間)
Rebecca Navarro
Rebecca Navarro 2015 年 9 月 30 日
コメント済み: Walter Roberson 2024 年 8 月 22 日 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)

回答 (1 件)

Jatin Singh
Jatin Singh 2024 年 8 月 22 日 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 件のコメント
Walter Roberson
Walter Roberson 2024 年 8 月 22 日 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');

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by