MATLAB Answers

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

5 views (last 30 days)
sami ullah
sami ullah on 4 Nov 2020
Commented: sami ullah on 6 Nov 2020
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?

Accepted Answer

Dave B
Dave B on 4 Nov 2020
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);
  3 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!