フィルターのクリア

want to calculate std_value and mean_value

4 ビュー (過去 30 日間)
bozheng
bozheng 2023 年 10 月 27 日
コメント済み: Star Strider 2023 年 10 月 27 日
below is my coding but i dont what happend i dont get data
------------------------
img1 = imread('SCM Data.jpg');
img = (-0.18 / (-0.28 / (45.39 / double(img1) - 1)) + 1) * 5.3;
std_value = std2(img);
mean_value = mean2(img);
fprintf('standard deviation:%.2f\n', std_value);
fprintf('average value:%.2f\n', mean_value);
-----------------------
by the way if i conducted calculate it will chage to

採用された回答

Star Strider
Star Strider 2023 年 10 月 27 日
There are 395449 ‘Inf’ values in ‘img’ (probably the result of the subtraction in the denominator of the transformation) so those are going to produce either Inf or NaN values in the mean and standard deviation. One way to deal with that is to assign all the Inf values to be NaN and then use the new fillmissing2 function (R2020a does not have it, and I am not certain what to suggest in its absence other than perhaps fillmissing and then hope for the best, since it seems to produce the same result) on each channel of ‘img’.
Then, do the statistics —
img1 = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1523076/image.jpeg');
img = (-0.18 / (-0.28 / (45.39 / double(img1) - 1)) + 1) * 5.3;
size(img)
ans = 1×3
755 869 3
nans = nnz(isnan(img)) % Check 'NaN' Values
nans = 0
infs = nnz(isinf(img)) % Check 'Inf' Values
infs = 395449
img(isinf(img)) = NaN; % Assign 'Inf' Values To 'NaN'
imgz = zeros(size(img));
for k = 1:size(img,3)
img(:,:,k) = fillmissing2(img(:,:,k), 'nearest');
imgz(:,:,k) = fillmissing(img(:,:,k), 'nearest');
end
std_value = std2(img);
mean_value = mean2(img);
fprintf('standard deviation:%.2f\n', std_value);
standard deviation:46.14
fprintf('average value:%.2f\n', mean_value);
average value:29.48
std_value = std2(imgz);
mean_value = mean2(imgz);
fprintf('standard deviation:%.2f\n', std_value);
standard deviation:46.14
fprintf('average value:%.2f\n', mean_value);
average value:29.48
This uses the provided image, that includes the borders and colorbar. (I did not crop it.) You will likely get different results from your actual image (that ideally should have been provided).
.
  2 件のコメント
bozheng
bozheng 2023 年 10 月 27 日
nans =
0
infs =
395449
Unrecognized function or variable 'fillmissing2'.
Error in
img(:,:,k) = fillmissing2(img(:,:,k), 'nearest');
Star Strider
Star Strider 2023 年 10 月 27 日
Just use fillmissing. When I checked (included in my code), it gave the same result as fillmissing2.
img1 = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1523076/image.jpeg');
img = (-0.18 / (-0.28 / (45.39 / double(img1) - 1)) + 1) * 5.3;
size(img)
ans = 1×3
755 869 3
nans = nnz(isnan(img)) % Check 'NaN' Values
nans = 0
infs = nnz(isinf(img)) % Check 'Inf' Values
infs = 395449
img(isinf(img)) = NaN; % Assign 'Inf' Values To 'NaN'
for k = 1:size(img,3)
img(:,:,k) = fillmissing(img(:,:,k), 'nearest');
end
std_value = std2(img);
mean_value = mean2(img);
fprintf('standard deviation:%.2f\n', std_value);
standard deviation:47.28
fprintf('average value:%.2f\n', mean_value);
average value:30.55
.

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

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 10 月 27 日
Here is the correct code:
img1 = imread('ALPS.jpg');
figure
imshow(img1); title('Original Image')
std_value1 = std2(img1);
mean_value1 = mean2(img1);
fprintf('Original Image: \n')
Original Image:
fprintf('standard deviation:%.5f\n', std_value1);
standard deviation:63.19555
fprintf('average value:%.5f\n', mean_value1);
average value:101.80412
img2 = (-0.18./(-0.28/(45.39./(img1)- 1))+1) * 5.3;
std_value2 = std2(img2);
mean_value2 = mean2(img2);
fprintf('Changed Image: \n')
Changed Image:
fprintf('standard deviation:%.5f\n', std_value2);
standard deviation:0.00000
fprintf('average value:%.5f\n', mean_value2);
average value:5.00000
figure
% See why std2 is giving '0'
imshow(img2), title('Changed Image')

カテゴリ

Help Center および File ExchangeFeature Detection and Extraction についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by