Find index of unique pixel values and assign a different pixel value to the grayscale image.

5 ビュー (過去 30 日間)
I have a grayscale image in which objects are represented as:
Object Pixel Value
Background 0
Class 1 1
Class 2 2
Class 3 3
Class 4 4
Class 5 5
There are no other pixel values except the 6 mentioned above. Background is essentially present, other objects may or may not be present.
The requirement is to assign different pixel value to the objects
Object Pixel Value New Pixel Value
Background 0 0
Class 1 1 50
Class 2 2 100
Class 3 3 150
Class 4 4 200
Class 5 5 250
For an example, i am attaching an image with Background, Class 4 and Class 5
What is the most optimized method to find and replace pixel values in a grayscale image?
  2 件のコメント
Rishi Raj
Rishi Raj 2022 年 7 月 31 日
Although similar.. i wanted to know the best way to change pixel values and keep a grayscale to grayscale image

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

採用された回答

Walter Roberson
Walter Roberson 2022 年 7 月 31 日
map = cast(0:50:250, class(Img));
NewImg = map(Img + 1);
Or more simply,
NewImg = Img .* 50;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by