How can i slip and rotate a color image?

2 ビュー (過去 30 日間)
Carole
Carole 2012 年 11 月 28 日
Hi,how can i slip and rotate the color image img like the binary image bw?
I=imread('image.jpg'); %color image
bw=segmentation(I); % the result is a binary image where the object detected (ROI) is white
img = bsxfun(@times, I, cast(bw,class(I)));
phy = regionprops(bw, 'Orientation')
[barx,bary]=barycentre(edge);
% slip the region to the center of the image
edge = recentre(edge,barx,bary);
I2 = recentre(bw,barx,bary);
phy1=phy.Orientation;
edge=imrotate(edge,-phy,'loose');
I3=imrotate(I2,-phy,'loose');
thanks
  4 件のコメント
Carole
Carole 2012 年 11 月 28 日
The function recenter and imrotate work with the binary image bw where the ROI is centred and rotated very well but when i want to center and rotate the ROI of the color image img it doesn't work :( . I couldn't use imtransform to center the region and rotate the image with a given angle -phy
yagnesh
yagnesh 2012 年 11 月 29 日
use imrotate after separating rgb planes and after that combine those 3 planes

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2012 年 11 月 29 日
Have you tried circshift() to slide the image over?
  7 件のコメント
Carole
Carole 2012 年 12 月 1 日
thanks it works with some modifications knowing that I want to move the centroid of the object to the center of the image
Image Analyst
Image Analyst 2012 年 12 月 1 日
OK great. Go ahead and mark it as "Answered" then.

サインインしてコメントする。

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 11 月 28 日
imrotate can rotate color images just fine:
imshow(imrotate(imread('peppers.png'),42,'crop'))
  2 件のコメント
Carole
Carole 2012 年 11 月 29 日
It seems that the problem is in the function recentre because it works with the binary image bw but it doesn't work with the color image img
I=imread('image.jpg'); %color image
bw=segmentation(I); % the result is a binary image where the object detected (ROI) is white
img = bsxfun(@times, I, cast(bw,class(I)));
edge2 = edge(bw, 'prewitt');
edge2 = 1 - edge2;
[barx,bary]=barycentre(edge2);
edge2 = recentre(edge2,barx,bary);
I2 = recentre(bw,barx,bary);
I3 = recentre(img,barx,bary);
The function
function im_trans=recentre(image,barx,bary)
[X,Y]=size(image);
tx=floor(X/2)-barx;
ty=floor(Y/2)-bary;
im_trans = zeros(X, Y);
if tx>=0
if ty>=0
for i=1 : X-tx
for j=1 : Y-ty
im_trans(i+tx, j+ty) = image(i, j);
end
end
elseif ty<0
for i=1 : X-tx
for j=abs(ty)+1 : Y
im_trans(i+tx, j+ty) = image(i, j);
end
end
end
elseif tx<0
if ty>=0
for i=abs(tx)+1 : X
for j=1 : Y-ty
im_trans(i+tx, j+ty) = image(i, j);
end
end
elseif ty<0
for i=abs(tx)+1 : X
for j=abs(ty)+1 : Y
im_trans(i+tx, j+ty) = image(i, j);
end
end
end
end
can you help me to correct it please
Image Analyst
Image Analyst 2012 年 11 月 30 日

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by