how do you change the color of a region of an image?

4 ビュー (過去 30 日間)
Alpha Macharia Wachira
Alpha Macharia Wachira 2021 年 6 月 22 日
回答済み: Ayush 2024 年 7 月 3 日
How do you do this by modifying the intensity(using scaling, adding or filtering) or simply zeroing (removing) them.

回答 (1 件)

Ayush
Ayush 2024 年 7 月 3 日
Hi,
To work on a certain region of an image, you need to define the coordinates and size of the region you want to modify. Assuming the region is rectangular in shape, define the "x_start" and "y_start" as the starting coordinates of the rectangle, along with width and height as its dimensions. After defining a region of interest, you can extract that region and work on it, either changing its intensity or zeroing it. Once you have edited the region, you can place the region back to the original image. Refer to an example pseudo code below for a better understanding of how you can extract the region and change its intensity using scaling:
% Read the image
img = imread('your_image.png');
% Define the region to modify (example: a rectangular region)
x_start = 50; y_start = 50; width = 100; height = 100;
% Extract the region
region = img(y_start:y_start+height-1, x_start:x_start+width-1, :);
% Scale the intensity (example: make it 50% brighter)
scaling_factor = 1.5;
region = uint8(double(region) * scaling_factor);
% Replace the region in the original image
img(y_start:y_start+height-1, x_start:x_start+width-1, :) = region;
% Display the modified image
imshow(img);
For zeroing, you can simply edit the above code with the below line:
% Zero the intensity of the region
img(y_start:y_start+height-1, x_start:x_start+width-1, :) = 0;

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by