白黒画像のランダムディザリングのアルゴリズム
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
今ランダムディザリングを既存のfunctionに頼らず書こうとしています。以下のコードでif文の論理演算子と行列インデックスでエラーが出てしまったのですが、解決方法がうまく見つけられず困っています。アドバイス頂けると幸いです。またランダムディザリングとしても考え方があっているか、間違っていればアドバイス頂けると幸いです。
以下コード
function result_im = random_dither(gray_im)
    in_rows = size(gray_im,1);
    in_cols = size(gray_im,2);
    result_im = zeros(in_cols,in_rows);
    for j= 0:in_rows-1
        for i=0:in_cols-1
            % r = a + (b-a).*rand(N,1) Nth randum numbers from a to b
            threshold = 0 + (255-0).*rand;
            if (gray_im(i,j) < threshold)
                result_im(i,j) = 0;
            else
                result_im(i,j) = 1;
            end
        end
    end
    figure, imshow(result_im);
end
以下エラー
添字インデックスは、実数の正の整数か、論理値のいずれかでなければなりません。
エラー: random_dither (line 9)
            if (gray_im(i,j) < threshold)
0 Kommentare
Antworten (2)
  Naoki Ishibashi
      
 am 19 Sep. 2017
        Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!