Image processing for pattern restoration

15 vues (au cours des 30 derniers jours)
Daeyeon Koh
Daeyeon Koh le 27 Mai 2024
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)

Réponse acceptée

Matlab Pro
Matlab Pro le 27 Mai 2024
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');

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by