Skew angle detection and correction in an image

46 visualizaciones (últimos 30 días)
Aliyu Abdu
Aliyu Abdu el 28 de Abr. de 2012
Comentada: abhishek m el 20 de Mzo. de 2018
Can anyone help with steps or code on how to perform skew correction in an image that is turned at a certain angle using Hough Transformation or any simpler/easier way. The image is turned at an angle and I want to correct it by straightening it. You can view a sample of the image at this URL:-
  1 comentario
Image Analyst
Image Analyst el 29 de Abr. de 2012
Rotation and spatial skewing are different things. Use imrotate to fix rotation, and imtransform to fix skewing.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 28 de Abr. de 2012
Possibly, after you've supplied more information such as telling us what is skewed (histogram, image, ?), where to find your sample image (what URL did you upload it to), why you need to use Hough, specifically, to do the correction instead of any other routine that might be easier or more suitable, etc.
[ Update] See this demo:
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
format compact;
% Read in a standard MATLAB color demo image.
folder = 'C:\Users\Aliyu\Documents\Temporary';
baseFileName = 'test2.tif';
% 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]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Make sure it's 8 bit gray scale, not 24 bit true color.
grayImage = rgb2gray(rgbImage);
% Binarize the image by thresholding.
binaryImage = grayImage > 128;
% Fill in the black letters so we just have a white block.
binaryImage = imfill(binaryImage, 'holes');
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Filled Image', 'FontSize', fontSize);
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage numberOfBlobs] = bwlabel(binaryImage, 8);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'Orientation');
allOrientations = [blobMeasurements.Orientation]
% Extract just one orientation (there should only be one in this image).
angleToRotate = -allOrientations(1);
% Rotate the image.
rotatedImage = imrotate(grayImage, angleToRotate);
% Display the rotated image.
subplot(2, 2, 3);
imshow(rotatedImage, []);
title('Rotated Image', 'FontSize', fontSize);
It doesn't get it quite right but that's because the corners of your rectangle are missing - they've been clipped off by the edges of the image. If those were in there it would get it perfectly.
  3 comentarios
Image Analyst
Image Analyst el 28 de Abr. de 2012
Looks like imrotate() should do it. You just need to figure out the angle. Maybe call regionprops and ask for the "orientation" - that's what I'd try. See my File Exchange for a demo, BlobsDemo.
abhishek m
abhishek m el 20 de Mzo. de 2018
in rotated image box its showing same image and filled image is not showing. please help me

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by