Cropping a bounded area using image processing
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone. I want to crop the traced area with image processing. What is the steps to do it?
My Code:
clc
clear all
close all
ei = 25;
st = 35;
k=ei*st;
img = imread('rrr.jpg');
h = ones(ei,st)/k;
I = imfilter(img,h,'symmetric');
figure
subplot(3,3,1), imshow(img), title('Orginal');
subplot(3,3,2), imshow(I), title('Filtered Image');
%Converting to BW
Igray = rgb2gray(I);
subplot(3,3,3), imshow(Igray), title('Grey');
I1 = imadjust(Igray,stretchlim(Igray),[]);
level = graythresh(I1);
BWj = imbinarize(I1,level);
dim = size(BWj);
IN = ones(dim(1),dim(2));
BW = xor(BWj,IN); %Inverting
subplot(3,3,4), imshow(BW), title('Black and White');
%Finding of an initial point
row = round(dim(1)/2);
col = min(find(BW(row,:)));
%Tracing
boundary = bwtraceboundary(BW, [row, col], 'W');
subplot(3,3,5), imshow(img), title('Traced');
hold on;
%Display traced boundary
plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);
hold off
%
The Output:

0 commentaires
Réponses (1)
yanqi liu
le 22 Jan 2022
clc
clear all
close all
ei = 25;
st = 35;
k=ei*st;
img = imread('rrr.jpg');
h = ones(ei,st)/k;
I = imfilter(img,h,'symmetric');
figure
subplot(3,3,1), imshow(img), title('Orginal');
subplot(3,3,2), imshow(I), title('Filtered Image');
%Converting to BW
Igray = rgb2gray(I);
subplot(3,3,3), imshow(Igray), title('Grey');
I1 = imadjust(Igray,stretchlim(Igray),[]);
level = graythresh(I1);
BWj = imbinarize(I1,level);
dim = size(BWj);
IN = ones(dim(1),dim(2));
BW = xor(BWj,IN); %Inverting
subplot(3,3,4), imshow(BW), title('Black and White');
%Finding of an initial point
row = round(dim(1)/2);
col = min(find(BW(row,:)));
%Tracing
boundary = bwtraceboundary(BW, [row, col], 'W');
subplot(3,3,5), imshow(img), title('Traced');
hold on;
%Display traced boundary
plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);
hold off
%
% crop it
[r,c] = find(BW);
rect = [min(c) min(r) max(c)-min(c) max(r)-min(r)];
img_rect = imcrop(img, rect);
subplot(3,3,6), imshow(img_rect), title('Croped');
0 commentaires
Voir également
Catégories
En savoir plus sur Subplots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!