-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshiftregion.m
More file actions
32 lines (25 loc) · 881 Bytes
/
Copy pathshiftregion.m
File metadata and controls
32 lines (25 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
% Demo to Shift a Region in a Binary Image
fontSize = 14;
grayImage = peaks(200);
subplot(2,2,1);
imshow(grayImage, []);
title('Original Grayscale Image','FontSize',fontSize);
axis on;
% Enlarge figure to full screen
set(gcf, 'units', 'normalized', 'outerposition',[0 0 1 1]); % Maximize Figure
binaryImage = grayImage > 5;
subplot(2,2,2);
imshow(binaryImage, []);
title('Binary Image','FontSize',fontSize);
axis on;
% Find Centroid of Binary Region
measurements = regionprops(binaryImage, 'Centroid');
[rows, columns] = size(binaryImage);
rowsToShift = round(rows/2 - measurements.Centroid(2));
columnsToShift = round(columns/2 - measurements.Centroid(1));
% Call circshift to move region to center
shiftedImage = circshift(binaryImage, [rowsToShift, columnsToShift]);
subplot(2,2,3);
imshow(shiftedImage, []);
title('Shifted Binary Image', 'FontSize', fontSize);
axis on;