Order of indexes when using rgb2ind

2 ビュー (過去 30 日間)
Jakob Sørensen
Jakob Sørensen 2014 年 3 月 31 日
コメント済み: Image Analyst 2014 年 4 月 2 日
Hi there,
I have some classified images in tif format (usually 3-4 classes), which I need to import to Matlab as an indexed image. Currently I am using
img = imread(<image name>.tif);
lbl = rgb2ind(img);
Which works fine, except for one slight issue. The order of the indexes (classes) seems somewhat random. This means that I cannot compare multiple images. Even if they are all classified the same way, using the same colors for the same classes. When they are imported to Matlab, it all gets mixed up.
So my questions are:
  1. Is there a (simple) way to control the order of the classes?
  2. How does rgb2ind() decide the order of the classes?
Any help which could help clarify this randomization mystery is much appreciated, thanks!

採用された回答

Image Analyst
Image Analyst 2014 年 3 月 31 日
If you simply call rgb2ind() on each image independently, you're going to get different mappings of colors to indexes. To prevent that you have to get the colormap of one image that you trust, and apply that to all the others:
% Get the initial colormap used on image #1.
[indexedImage1, colorMap] = rgb2ind(rgbImage1);
% Now use that colormap for a different image.
indexedImage2 = rgb2ind(rgbImage2, colorMap);
In this way, all images will be colored the same way.
  2 件のコメント
Jakob Sørensen
Jakob Sørensen 2014 年 4 月 1 日
編集済み: Jakob Sørensen 2014 年 4 月 2 日
I will try that once I have the time, and let you know if it works. Sounds promising though... :-)
Update: Got to try it, and it works perfectly. Thank you very much, you just saved me a bunch of time!
Image Analyst
Image Analyst 2014 年 4 月 2 日
You're welcome. Glad I could help. Thanks for Accepting the answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrange についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by