Image processing for pattern restoration

조회 수: 13 (최근 30일)
Daeyeon Koh
Daeyeon Koh 2024년 5월 27일
답변: Matlab Pro 2024년 5월 27일
Hi.
I am working on restoring unclearly printed rectangular patterns using MATLAB. All original patterns are exact rectangular, and I am taking photos for collecting original printed images by a camera. The attached images show the original image used (first), the filled image extracted through the written code (second), and the desired final image (third). My goal is to achieve an image like the third one. The edges do not need to be perfectly rectangular; a rough restoration is sufficient. Any clue would be helpful to me. Thank you.
clc; clear;
imFile="image1.jpg";
Image_Original=imread(imFile);
Image_Gray=rgb2gray(Image_Original);
Image_Inversed = imcomplement(Image_Gray);
Image_BW = imbinarize(Image_Inversed);
Image_BW_filled = imfill(Image_BW,"holes");
edges = edge(Image_BW_filled, 'Canny');
imshow(Image_BW_filled)

채택된 답변

Matlab Pro
Matlab Pro 2024년 5월 27일
Hi
Finiding the 4 corners of the rectangle - is very easy (looking for minimum/maximum non zero index on each dimention)
Here is a small example:
W = 20; H = 120;
Image_BW_filled = zeros(W*3,H*1.2);
Image_BW_filled(W*1:W*2-1,20:H+20-1) = rand(W,H)> 0.1;
hFig = figure;
ax = axes('Parent',hFig);
imshow(Image_BW_filled,'Parent',ax)
x1 = find(sum(Image_BW_filled)>0,1, 'first');
x2 = find(sum(Image_BW_filled)>0,1, 'last');
y1 = find(sum(Image_BW_filled,2)>0,1, 'first');
y2 = find(sum(Image_BW_filled,2)>0,1, 'last');
corners = [...
x1,y1; ...
x1,y2; ...
x2,y1; ...
x2,y2];
hold(ax,'on');
hLine = line('XData',corners(:,1),'YData',corners(:,2),'Parent',ax,'Marker','o','MarkerFaceColor','r','LineStyle','none');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by