图像旋转不正确 - Matlab
Incorrect rotation of image - Matlab
如何在分离的图形中绘制旋转的裁剪图像,我没有得到正确的旋转(例如,k= 3 或 6)的问题是什么?
代码:
clear;
clc;
RGB = imread('pillsetc.png');
I = rgb2gray(RGB);
bw = imbinarize(I);
bw = bwareaopen(bw,30);
bw = imfill(bw,'holes');
imshow(bw)
[B,L] = bwboundaries(bw,'noholes');
imshow(bw)
[labeledImage, numBlobs] = bwlabel(bw);
for k = 1 : numBlobs
thisObject = ismember(labeledImage, k);
measurements = regionprops(thisObject, 'Orientation', 'BoundingBox');
croppedImage = imcrop(RGB, measurements.BoundingBox);
angle = measurements.Orientation
uprightImage = imrotate(croppedImage, angle);
imshow(uprightImage);
hold on
end
问题是当你得到物体的角度时,如果你想让它们水平,你必须这样做:
uprightImage = imrotate(croppedImage, -angle);
而不是:
uprightImage = imrotate(croppedImage, angle);
如果我运行马里奥的这个代码:
clear;
clc;
RGB = imread('Small-mario.png');
I = rgb2gray(RGB);
bw = imbinarize(I);
bw = bwareaopen(bw,30);
bw = imfill(bw,'holes');
figure;
imshow(bw)
[B,L] = bwboundaries(bw,'noholes');
figure;
imshow(bw)
[labeledImage, numBlobs] = bwlabel(bw);
for k = 1 : numBlobs
thisObject = ismember(labeledImage, k);
measurements = regionprops(thisObject, 'Orientation', 'BoundingBox');
croppedImage = imcrop(RGB, measurements.BoundingBox);
angle = measurements.Orientation;
uprightImage = imrotate(croppedImage, -angle);
figure;
imshow(uprightImage);
end
之后马里奥的头是水平的:
如何在分离的图形中绘制旋转的裁剪图像,我没有得到正确的旋转(例如,k= 3 或 6)的问题是什么?
代码:
clear;
clc;
RGB = imread('pillsetc.png');
I = rgb2gray(RGB);
bw = imbinarize(I);
bw = bwareaopen(bw,30);
bw = imfill(bw,'holes');
imshow(bw)
[B,L] = bwboundaries(bw,'noholes');
imshow(bw)
[labeledImage, numBlobs] = bwlabel(bw);
for k = 1 : numBlobs
thisObject = ismember(labeledImage, k);
measurements = regionprops(thisObject, 'Orientation', 'BoundingBox');
croppedImage = imcrop(RGB, measurements.BoundingBox);
angle = measurements.Orientation
uprightImage = imrotate(croppedImage, angle);
imshow(uprightImage);
hold on
end
问题是当你得到物体的角度时,如果你想让它们水平,你必须这样做:
uprightImage = imrotate(croppedImage, -angle);
而不是:
uprightImage = imrotate(croppedImage, angle);
如果我运行马里奥的这个代码:
clear;
clc;
RGB = imread('Small-mario.png');
I = rgb2gray(RGB);
bw = imbinarize(I);
bw = bwareaopen(bw,30);
bw = imfill(bw,'holes');
figure;
imshow(bw)
[B,L] = bwboundaries(bw,'noholes');
figure;
imshow(bw)
[labeledImage, numBlobs] = bwlabel(bw);
for k = 1 : numBlobs
thisObject = ismember(labeledImage, k);
measurements = regionprops(thisObject, 'Orientation', 'BoundingBox');
croppedImage = imcrop(RGB, measurements.BoundingBox);
angle = measurements.Orientation;
uprightImage = imrotate(croppedImage, -angle);
figure;
imshow(uprightImage);
end
之后马里奥的头是水平的: