Algorithm conversion with code generation

3 ビュー (過去 30 日間)
Chan KitHoe
Chan KitHoe 2017 年 9 月 16 日
コメント済み: Image Analyst 2017 年 9 月 17 日
Hi all, I am working on an algorithmic function and I'd like to convert it into C. Code as stated below,
ImgR= Input(:,:,1); % Red colour channel.
ImgG= Input(:,:,2); % Green colour channel.
ImgB= Input(:,:,3); % Blue colour channel.
However while converting, I ran into an error stating - "Index expression out of bounds. Attempted to access element 2. The valid range is 1-1." How can I resolve this issue? Thanks!

回答 (1 件)

John D'Errico
John D'Errico 2017 年 9 月 16 日
You don't have a color image. You have a purely grayscale image. So trying to extract the red green and blue planes is waste of time.
So you need to convert the grayscale image to three channel color, most simply done by replicating the gray image into three color planes, or use an appropriate tool to do a better job. Or work with a color image to start with.
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 9 月 17 日
if ndims(Input) > 2
ImgR= Input(:,:,1); % Red colour channel.
ImgG= Input(:,:,2); % Green colour channel.
ImgB= Input(:,:,3); % Blue colour channel.
else
ImgR = Input;
ImgG = Input;
ImgB = Input;
end
Image Analyst
Image Analyst 2017 年 9 月 17 日
Even though MATLAB is case sensitive, I don't think it's a good idea to name variables after built-in functions, even if the capitalization is different.

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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by