我有近1000张类似数据集的图像,它们都有黑色背景和物体(皮肤癌痣)。现在问题很明显,即物体处于不同的方向,我希望所有图像中的物体具有相同的方向。
建议使用MATLAB代码。
答案 0 :(得分:3)
回答: 检查下面显示的皮肤病变痣的两个图像:
我们假设它来自文件夹(1000张图像)上的循环,它们位于:
Code:
% I1= first image
I=imread(I1); %% Image input
BW = im2bw(I,0.004);
%%%%% Getting the biggest region (because if segmentation give unclear results)
[L, num] = bwlabel(BW, 8);
count_pixels_per_obj = sum(bsxfun(@eq,L(:),1:num));
[~,ind] = max(count_pixels_per_obj);
biggest_region = (L==ind);
%%%%%%
%%% getting orientation
s = regionprops(biggest_region, 'Orientation');
data=s.Orientation;
%%% Orientation end
Y = imrotate(I, -data, 'loose', 'bilinear');
figure;
imshow(Y)
%%% Now the rotated image will be shown as
%% Now write the image in any other folder
%% that have all images aligned
imwrite(Y, 'test.jpg');
%% Hope it will save time for other. Thanks