Cropping a bounded area using image processing

조회 수: 6 (최근 30일)
Ilker Dogan
Ilker Dogan 2022년 1월 21일
답변: yanqi liu 2022년 1월 22일
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:

답변 (1개)

yanqi liu
yanqi liu 2022년 1월 22일
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');

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by