MATLAB: How can we replacing the pixel values of RGB image under bounding box with some random pixel values

bounding boxMATLABreplace pixel values

I have the following code:
clear all
clc
faceDetector = vision.CascadeObjectDetector;
I = imread('visionteam.jpg');
figure, imshow(I), title('Input Image');
bboxes = step(faceDetector, I);
IFaces = insertObjectAnnotation(I, 'Rectangle', bboxes, 'Face');
figure, imshow(IFaces), title('Detected faces');
———————
I want to replace the pixel values of RGB image under bounding box with some random pixel values?
After replacing the pixel values under bounding box, how can i show the complete image with replaced pixel values under bounding box?

Best Answer

Hi Sami:
It sounds like you want to set the RGB pixel value for the values in the bounding boxes. You can extract the rows and columns from the 'bboxes' variable, and then set those on the image matrix (or take a copy of the matrix to avoid altering the original). Below I show an example where I make all of the pixels in the first bounding box red. I then show the altered image using the imshow function.
% Each row of bboxes has a X, Y, width, height
cols=bboxes(1,1):sum(bboxes(1,[1 3]));
rows=bboxes(1,2):sum(bboxes(1,[2 4]));
% Make bbox 1 red:
I(rows,cols,1)=255;
I(rows,cols,2)=0;
I(rows,cols,3)=0;
figure, imshow(I);