フィルターのクリア

How can we generate an image with equal number of intensity values?

1 回表示 (過去 30 日間)
Navdeep Sony
Navdeep Sony 2016 年 1 月 31 日
コメント済み: Image Analyst 2016 年 1 月 31 日
For example we have an image that has 5 pixels with intensity 100, 5 with intensity 50, 5 with intensity 200 and so on.
  1 件のコメント
Image Analyst
Image Analyst 2016 年 1 月 31 日
Do all gray levels have an equal number of occurrence, or do you want to specify exactly what gray levels occur and for how many pixels each gray level occurs? If all have equal, then you want histogram equalization, but not like most people do it. You'd have to use special code.

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

採用された回答

Walter Roberson
Walter Roberson 2016 年 1 月 31 日
needHeight = 96; needWidth = 78; %adjust as required
default_pix_intens = 0; %default intensity if the template does not describe enough pixels
template = [5, 100; %count, intensity
5, 50;
5, 200];
num_pix_needed = needHeight * needWidth;
pixdata = [];
for K = 1 : size(template,1)
pixdata = [pixdata, repmat(template(K,2), 1, template(K,1))];
end
num_pix_templated = length(pixdata);
if num_pix_templated > num_pix_needed
error( fprintf('only %d total pixels needed but template describes %d pixels', num_pix_needed, num_pix_templated) );
elseif num_pix_templated < num_pix_needed
pixdata(num_pix_templated+1 : num_pix_needed) = default_pix_intens;
end
scrambled_pixdata = pixdata(randperm(numel(pixdata))); %assuming you want a random order
pix_matrix = reshape(scrambled_pixdata, needHeight, needWidth);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by