I want to normalize the orientation and scale of these images before I do a similarity measure. How can I achieve this using PCA? Is there any other ways?
MATLAB: Normalize image orientation and scale
Image Processing Toolboxnormalizerotation
Related Solutions
I'm finding a difference. Run my demo. It's based on yours but I cleaned it up a bit to be far more illustrative, and I used a standard demo image.
clc;clearvars;close all;workspace;fontSize = 16;% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');if ~exist(folder, 'dir') % If that folder does not exist, don't use a folder
% and hope it can find the image on the search path.
folder = [];endbaseFileName = '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(3, 3, 1);imshow(grayImage, []);title('Original Grayscale Image', 'FontSize', fontSize);% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);% Compute Radon Transform.
theta= 0:1:179;[R,xp]= radon(grayImage,theta);[n,l]=size(R);subplot(3, 3, 2);imshow(R, []);title('R Image', 'FontSize', fontSize);% Determine the middle row.
middleRow = floor(n/2);% Extract and plot the middle row after rotation.
points=R(middleRow, 1 : 180);subplot(3, 3, 3);plot(points, 'b+-');title('points', 'FontSize', fontSize);% Rotate the image by 2 degrees.
rotatedImage = imrotate(grayImage,2); % rotation de 2°
% Display the original gray scale image.subplot(3, 3, 4);imshow(rotatedImage, []);title('Rotated Grayscale Image', 'FontSize', fontSize);% Compute Radon Transform.R_rotation = radon(rotatedImage,theta);subplot(3, 3, 5);imshow(R_rotation, []);title('R rotation Image', 'FontSize', fontSize);% Extract and plot the middle row after rotation.Points_apres_rotation = R_rotation(middleRow,1 : 180);subplot(3, 3, 6);plot(R_rotation, 'b+-');title('Points apres rotation', 'FontSize', fontSize);% Construct difference between middle rows.
diffPoints = points - Points_apres_rotation;subplot(3, 3, 8);plot(diffPoints, 'b+-');title('Difference between rows', 'FontSize', fontSize);
Convert to grayscale and then threshold and find the bounding box
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. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;format compact;fontSize = 20;% Read in the color image.
folder = pwd;baseFileName = 'm2.bmp';% 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; endendrgbImage = imread(fullFileName);% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);% Display the original color image.
subplot(2, 3, 1);imshow(rgbImage, []);axis on;title('Original Color Image', 'FontSize', fontSize);drawnow;% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);% Histogram the red channel, but there is a huge spike at 255 so let's not count those.
subplot(2, 3, 2);grayImage = rgb2gray(rgbImage);imshow(grayImage, []);title('Gray Scale version', 'FontSize', fontSize);subplot(2, 3, 3);histogram(grayImage(grayImage<255))grid on;title('Histogram of Gray Scale Image', 'FontSize', fontSize);someThresholdValue = 150;binaryImage = grayImage > someThresholdValue;% Take largest blob
binaryImage = bwareafilt(binaryImage, 1);subplot(2, 3, 4);imshow(binaryImage);grid on;title('Binary Image', 'FontSize', fontSize);% Label the binary image.
labeledImage = bwlabel(binaryImage);props = regionprops(labeledImage, 'BoundingBox');bbox = props.BoundingBoxcroppedImageRGB = imcrop(rgbImage, bbox);subplot(2, 3, 5);imshow(croppedImageRGB);grid on;title('Cropped RGB Image', 'FontSize', fontSize);% Gray scale version of cropped image
croppedImageGray = imcrop(grayImage, bbox);subplot(2, 3, 6);imshow(croppedImageGray);grid on;title('Cropped Gray Scale Image', 'FontSize', fontSize);
Related Question
- I have following code of image extraxtion but i got gray scale image output while giving input color image ,how could i get the color image output
- How to separate the whole lip image into upper and lower part using code
- How to display the input image, after when the threshold values exceeds certain limit
- Adding Noise to the Image
Best Answer