필터 지우기
필터 지우기

In binary image, how to convert large black pixels area into white ?

조회 수: 4 (최근 30일)
Y.L.K KHUMAN
Y.L.K KHUMAN 2017년 12월 7일
댓글: Y.L.K KHUMAN 2017년 12월 9일
I am working on skew detection and correction. I had corrected the skewness of the image, but I found that there is large size of Black areas on all sides of the corrected image. I tried to convert the black pixels (large area only) to white using the following codes. But it is not working properly. Sometimes its also remove black pixel from the pictures itself and sometimes it does not remove the larger area of the black pixels.
<<
>>
measurements = regionprops(SkewCorrectedImage == 0, 'Area','PixelIdxList');
Regions = find([measurements.Area] >=200000);%%
theIndexes = vertcat(measurements(Regions).PixelIdxList);
c=SkewCorrectedImage;
(theIndexes)=1
  댓글 수: 2
Jan
Jan 2017년 12월 7일
You should be able to set the added pixels to white directly in the code for rotating the image. This would be much smarter that using an auto-detection of the black triangles afterwards. So please post the code to obtain the shown image.
Y.L.K KHUMAN
Y.L.K KHUMAN 2017년 12월 7일
편집: Y.L.K KHUMAN 2017년 12월 7일
Here is the rotation part code:
props = regionprops(joinedBlobs, 'BoundingBox','Orientation'); % Find bounding box.
boundingBox = props.BoundingBox;
angle = props.Orientation
angleToRotate = -angle(1);
figure, imshow(IPImg), rectangle('Position', boundingBox, 'EdgeColor', 'red');
croppedImage = imcrop(IPImg, props.BoundingBox);
figure, imshow(croppedImage), title('cropped Image');
SkewCorrectedImage = imrotate(croppedImage, angleToRotate);
figure, imshow(SkewCorrectedImage), title('corected image');
imsave();

댓글을 달려면 로그인하십시오.

답변 (1개)

Akira Agata
Akira Agata 2017년 12월 7일
You can easily do that by using imclearborder function, like:
BWout = ~yourBinaryImage;
BWout = imclearborder(BWout);
BWout = ~BWout;
  댓글 수: 1
Y.L.K KHUMAN
Y.L.K KHUMAN 2017년 12월 9일

Thank for your help. When I try this code, it removes some boundary part, which is also a part of the image. Rotated Image:

After Using your code:

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geometric 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