How can I mirror a face image?
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to mirror a face image by matlab, how can I do it? For example imagine that we split our face image by a vertical line and we want to mirror this 2 parts!what is the code?
댓글 수: 0
답변 (1개)
Image Analyst
2014년 4월 21일
See code below to produce this image:
% Demo to mirror an image down the middle.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 22;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Get a flipped version
flippedRGBImage = fliplr(rgbImage);
subplot(2, 2, 2);
imshow(flippedRGBImage);
title('Mirrored Color Image', 'FontSize', fontSize);
% Replace right half with with right half of flipped image.
midColumn = ceil(columns/2);
outputImage = rgbImage; % Initialize
outputImage(:, midColumn:end, :) = flippedRGBImage(:, midColumn:end, :);
subplot(2, 2, 3);
imshow(outputImage);
title('Final Color Image', 'FontSize', fontSize);
Note that if you have an old version you're going to have to use a different function that fliplr() since that was only changed to handle color images with the R2014a version.
Feel free to adapt as needed to fit your situation.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!