You are currently viewing Matlab Code for Region of Interest in Image

Matlab Code for Region of Interest in Image

Spread the love

Overview of ROI Processing

It is sometimes of interest to process a single subregion of an image, leaving other regions unchanged. This is commonly referred to as region-of-interest (ROI) processing. Image sub regions may be conveniently specified by using Mathematica Graphics primitives, such as Point, Line, Circle, Polygon, or simply as a list of vertex positions.

A region of interest (ROI) is a portion of an image that you want to filter or perform some other operation on. You define an ROI by creating a binary mask, which is a binary image that is the same size as the image you want to process with pixels that define the ROI set to 1 and all other pixels set to 0.

You can define more than one ROI in an image. The regions can be geographic in nature, such as polygons that encompass contiguous pixels, or they can be defined by a range of intensities. In the latter case, the pixels are not necessarily contiguous.


Using Binary Images as a Mask

This section describes how to create binary masks to define ROIs. However, any binary image can be used as a mask, provided that the binary image is the same size as the image being filtered.

Matlab Code for Region of Interest in Image

close all;
% Read Input Image


%Resize the Image

InputImage=imresize(InputImage,[256 256]);

% Display the Image


% Get Inputs from Mouse,Select 4 Seed Points in Image

[Col Row]=ginput(4);

c =Col;
r =Row;

% Select polygonal region of interest
BinaryMask = roipoly(InputImage,c,r);
figure, imshow(BinaryMask);title('Selected Region of Interest');

%Create Buffer for ROI

%Create Buffer for NONROI
for i=1:256

for j=1:256

if BinaryMask(i,j)==1




%Display ROI and Non ROI
subplot(1,2,2);imshow(NONROI,[]);title('NON ROI');