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!