Image processing Image rotation
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi
when I am rotating image it get jaggies means edges are beacome zig zag the staircase effect comes can any one have the solution of this problem?
댓글 수: 0
답변 (2개)
Image Analyst
2012년 6월 22일
Try this code to average the jaggies with the background (antialias). Bascially I'm just dividing the perimeter pixels by 2:
clc;
clearvars;
close all;
workspace;
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- 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 in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
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(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale 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')
% rotate it by 10 degrees
rotatedImage = imrotate(grayImage, 5);
% Display the image.
subplot(2, 2, 2);
imshow(rotatedImage, []);
title('Rotated Image with Jaggies', 'FontSize', fontSize);
% Find the perimeter
binaryImage = bwperim(rotatedImage);
% Display the image.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Perimeter', 'FontSize', fontSize);
% Anti-alias by averaging where the perimeter is only.
noJaggiesImage = rotatedImage; % Initialize
% Now average only where there is a perimeter pixel.
noJaggiesImage(binaryImage) = noJaggiesImage(binaryImage)/2;
% Display the image.
subplot(2, 2, 4);
imshow(noJaggiesImage, []);
title('Jaggies averaged away', 'FontSize', fontSize);
if you want, you can use conv2() to replace the pixel with the average in a bigger window. It's a little more complicated but I'm sure you can handle it.
댓글 수: 0
DGM
2023년 12월 30일
편집: DGM
2023년 12월 31일
IPT imrotate() has supported interpolation since at least R2009b.
% an image
% inverted so that the edges have contrast against the padding
% this specific image is logical-class, so make it numeric
% otherwise, there are no intermediate values to interpolate
inpict = im2uint8(~imread('blobs.png'));
% just specify the interpolation
outpict = imrotate(inpict,45,'bilinear');
% show it
imshow(outpict,'border','tight')
% zoom in so that edges are visible on the forum
xlim([50 200])
ylim([85 175])
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!