필터 지우기
필터 지우기

Skew angle detection and correction in an image

조회 수: 26 (최근 30일)
Aliyu Abdu
Aliyu Abdu 2012년 4월 28일
댓글: abhishek m 2018년 3월 20일
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
Image Analyst
Image Analyst 2012년 4월 29일
Rotation and spatial skewing are different things. Use imrotate to fix rotation, and imtransform to fix skewing.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2012년 4월 28일
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
Image Analyst
Image Analyst 2012년 4월 28일
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 2018년 3월 20일
in rotated image box its showing same image and filled image is not showing. please help me

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by