|
Just mask it out, like in this demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Program Files\MATLAB\R2010b\toolbox\images\imdemos';
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(1, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Set rectangle.
x1 = 80;
y1 = 35;
width = 95;
height = 75;
outputImage = grayImage; % Initialize
% Zero out the edges (margins).
% Zero top
outputImage(1:y1-1, :) = 0;
% Zero bottom
outputImage(y1+height:end, :) = 0;
% Zero left.
outputImage(y1:y1+height-1, 1:x1-1) = 0;
% Zero right.
outputImage(y1:y1+height-1, x1+width:end) = 0;
% Display the original gray scale image.
subplot(1, 2, 2);
imshow(outputImage, []);
title('Masked Image', 'FontSize', fontSize);
|