Re: 關於這段code是如何達到顯示color histogram的?已回收
※ 引述《transpotting (transpotting)》之銘言:
大家好,我前些時候在code job板發了一個案子
是自己在研究上需要用到的,有關影像分析部分的project
由於我本身並非念資工系背景,但是研究上有需要所以才發案請人幫忙
目前也在一邊研究別人code一邊學習中
我想問的就是下面這段code是如何達到"取得image的histogram的功能"
(%%後的中文註解是我稍微研究後認為的結果,麻煩強者板有幫忙指正,感謝)
function hist = gethist(file_name, type) %% 定義取得質方圖的函式get_hist?
firstframe = imread(file_name); %% 不是很了解firstframe的功能?
hist = get_hist(firstframe, type); %% 是為了定義的get_hist可以read image?
end
function color_hist = get_hist(array, type) %% 將color_hist這個函式的結果傳給取
%% 得質方圖的函式get_hist?
ss = size(array);
hist = zeros(ss(1),ss(2)); %% 基本上就是 hist = zeros(size(array));
if type == 'RGB' %% 建立一個跟 array 一樣大的零矩陣
% use 64 (4*4*4) bins to do histogram
hist(:,:) = floor(double(array(:,:,1))/64)*16 +
floor(double(array(:,:,2))/64)*4 +
floor(double(array(:,:,3))/64);
color_hist = zeros(1,64);
%% 上面四行直接看成 RGB 轉 Grayscale
%% 應該會比較好理解
還有因為image的dataset圖片大小不同,所包含的pixels數目也不同
所以要normalization
但是我也不是很了解下面這段code是怎麼做到的
for i =1:ss(1)
for j = 1:ss(2)
color_hist(hist(i,j)+1) = color_hist(hist(i,j)+1)+1;
end
end
color_hist = double(color_hist) / sum(color_hist);
到最後 color_hist 會是 vector 各個 element 代表各個灰度
的 pixel 數,當然 sum(color_hist) = 總 pixel 數,剩下應該很好理解。
先感謝利害的強者回答了 orz 非常感恩!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 71.95.57.98
→
05/14 14:30,
05/14 14:30
→
05/14 14:30,
05/14 14:30
--
※ 發信站: 批踢踢實業坊(ptt.cc)
※ 編輯: DigiPrince 來自: 140.113.94.230 (05/14 15:03)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 4 篇):