how to trace the location of a rotated image im matlab???

4 views (last 30 days)
suppose i have an image, the image is rotated to some axis. now this image has some region "Black" around it (as it is now rotated), i want to identify the location of this image , like after Black portion from which location image started ,and at which location is the 1st border of image and second border ,untill whole image location is traced. i am very confused how to do???
  2 Comments
Image Analyst
Image Analyst on 27 Jul 2011
You're confused? How about us, who are trying to figure out what you're talking about? How about you do a better job of defining exactly what "location of this image" means to you. Do you want to get the coordinates of all the boundary pixels after it's been rotated? If so, why? Why do you want to trace this image? Have you looked at bwboundaries()?
blue ice
blue ice on 27 Jul 2011
yes i want to get the boundary pixel coordinated of image;
and i dont have a binary image,its .jpg

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 27 Jul 2011
This should work well for most images. If your image has wavy irregular zeros around its outer edges then it will require some adaptation but for the vast majority of images this will work. 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. workspace; % Make sure the workspace panel is showing. fontSize = 20;
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% 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
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, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Rotate the image
rotatedImage = imrotate(grayImage, 30);
% Display the image.
subplot(2, 2, 2);
imshow(rotatedImage, []);
title('Rotated Image', 'FontSize', fontSize);
% Find pixels which are not the zeros touching the border
binaryImage = rotatedImage > 0;
% Get rid of any "bays" where the original image may have had
% zeros on it's border.
binaryImage = bwconvhull(binaryImage);
% Display the image.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Now find the boundaries
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
boundaries = bwboundaries(binaryImage);
% Display the rotated image again.
subplot(2, 2, 4);
imshow(rotatedImage, []);
title('Rotated Image with Boundary overlaid', 'FontSize', fontSize);
% Plot all the borders on the rotated grayscale image using the coordinates returned by bwboundaries.
hold on;
numberOfBoundaries = size(boundaries); % Only 1 boundary for this cameraman example.
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
xCoordinates = thisBoundary(:,2);
yCoordinates = thisBoundary(:,1);
plot(xCoordinates, yCoordinates, 'r', 'LineWidth', 3);
end
hold off;
msgbox('Done with demo!');

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!