# MATLAB: Rotate individual labelled/segmented characters about its centroid

rotate characters

Hi ,
How do I rotate the individual characters anti-clockwise 90 degrees about their own centroid?
I have obtained their centroids and other stuff:
Character # Mean Intensity Centroid(X) Centroid(Y) Area
# 1 54.8 16.7 57.6 109.0
# 2 62.8 33.5 57.6 136.0
# 3 79.5 51.5 57.3 106.0
# 4 66.1 59.9 28.1 145.0
# 5 62.4 68.1 56.7 100.0
# 6 65.6 77.2 29.0 100.0
# 7 55.4 85.6 55.2 56.0
# 8 55.5 94.9 26.0 50.0
# 9 67.3 100.2 56.9 118.0
#10 76.5 118.1 27.0 117.0
#11 65.7 116.6 56.4 118.0
#12 71.1 132.8 25.8 139.0
#13 59.9 130.7 53.2 102.0
#14 81.9 150.1 55.5 115.0
Things I have tried:
1.) tried cropping and rotate but could not crop individual characters and rotate
2.) Tried using BW2 = bwareafilt(BW,range) and rotate but the character rotate about the image centroid instead
3.) Wanted to tried bounded box but do not know how to write those codes
My codes
clear all;I=imread('charact2.jpg');J=imrotate(I,-180);%Upright imagesubplot(3, 3, 1);imshow(J);% Convert to binary imageJ = im2bw(J,0.34);%Remove symbol (row,column), convert to 1J(6:42,7:41)=0;subplot(3, 3, 2);imshow(J)% Identify each character by seeing which pixels are connected to each other.labeledImage = bwlabel(J,8);    coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); subplot(3, 3, 3);imshow(coloredLabels)% Get all the char properties. Measurements = regionprops(labeledImage,J,'all');numberOfchar = size(Measurements, 1);%get the centroids of ALL the charfprintf(1,'Character #    Mean Intensity  Centroid(X) Centroid(Y)  Area\n')for k = 1 : numberOfcharxCenter = Measurements(k).Centroid(1);yCenter = Measurements(k).Centroid(2);Pixels = Measurements(k).PixelIdxList;Intensity = mean(I(Pixels));CharArea = Measurements(k).Area;charOrientation = Measurements(k).Orientation;fprintf(1,'#%2d %18.1f %13.1f %12.1f %12.1f\n', k,Intensity, xCenter, yCenter, CharArea);end

another = zeros(size(J));for k =1:numberOfchar    croppedImage = imcrop(J, Measurements(k).BoundingBox);    angle = 90;    rotated = imrotate(croppedImage, angle);    center_x = Measurements(k).Centroid(1);    center_y = Measurements(k).Centroid(2);    [rows, cols] = size(croppedImage);    prev_x = round(center_y - cols/2);    prev_y = round(center_x - rows/2);    another(prev_x:prev_x+cols-1,prev_y:prev_y+rows-1) = rotated;endimshow(another)