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 Center および File ExchangeSubplots についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by