Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
Alpha Macharia Wachira
Alpha Macharia Wachira el 22 de Jun. de 2021
Respondida: Ayush el 3 de Jul. de 2024
How do you do this by modifying the intensity(using scaling, adding or filtering) or simply zeroing (removing) them.

Respuestas (1)

Ayush
Ayush el 3 de Jul. de 2024
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;

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by