フィルターのクリア

Coloring the largest component with different color than others

2 ビュー (過去 30 日間)
Sultan
Sultan 2017 年 7 月 12 日
回答済み: Prashant Arora 2017 年 7 月 17 日
Hello all,
I am looking to mark the largest connected component in an image with special color say 'red', and then color the other components in black while the empty space I wanted to be colored in white.Here are my codes.
  1 件のコメント
Sultan
Sultan 2017 年 7 月 12 日
A=rand(100);
B=A<.5
CC = bwconncomp(B,4)
numOfPixels = cellfun(@numel,CC.PixelIdxList)
[unused,indexOfMax] = max(numOfPixels)
biggest = zeros(size(B))
biggest(CC.PixelIdxList{indexOfMax}) = 1
colours=[1 1 1;1 0 0;0 0 0]
colormap (colours)
imagesc(biggest)

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

回答 (1 件)

Prashant Arora
Prashant Arora 2017 年 7 月 17 日
Hi Sultan,
You can use the method below to achieve your use-case.
image = zeros(size(biggest,1),size(biggest,2),3);
NotBiggest = B - biggest;
image(:,:,1) = biggest + 1*NotBiggest;
image(:,:,2) = 0*biggest + 1*NotBiggest;
image(:,:,3) = 0*biggest + 1*NotBiggest;
imagesc(image);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by