how to split image to 3 parts

조회 수: 17 (최근 30일)
amr elslene
amr elslene 2021년 12월 30일
댓글: Meg Noah 2022년 1월 2일

채택된 답변

Image Analyst
Image Analyst 2021년 12월 30일
Like top third, left bottom panel, and right bottom panel? Is the image the same size every time so that all dividing rows and column can be determined in advance?
[rows, columns, numberOfColorChannels] = size(rgbImage);
row1 = round(rows/3);
col1 = round(columns/2);
topThird = rgbImage(1 : row1, :, :);
leftPanel = rgbImage(row1 + 1 : end, 1 : col1, :);
rightPanel = rgbImage(row1 + 1 : end, col1 + 1 : end, :);
  댓글 수: 8
amr elslene
amr elslene 2021년 12월 31일
편집: amr elslene 2021년 12월 31일
all i need is take like that
from plat like that
Thanks in advance @Image Analyst
Image Analyst
Image Analyst 2021년 12월 31일
@amr elslene, well it would have been nice to know that before.
See attached demo. It will be easy to adapt it to find characters once you have extracted each panel.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Meg Noah
Meg Noah 2022년 1월 2일
Here are two ways:
close all
clear
clc
[imdata,~] = imread('image.jpeg');
% split into three color channels of equal size
imRed = squeeze(imdata(:,:,1));
imGreen = squeeze(imdata(:,:,2));
imBlue = squeeze(imdata(:,:,3));
figure()
subplot(2,2,1)
imagesc(imRed)
axis off; axis equal;
colormap(gca,'gray')
title('Red')
subplot(2,2,2)
imagesc(imGreen)
axis off; axis equal;
colormap(gca,'gray')
title('Green')
subplot(2,2,3)
imagesc(imBlue)
axis off; axis equal;
colormap(gca,'gray')
title('Blue')
subplot(2,2,4)
imagesc(imdata)
axis off; axis equal;
title('Color Composite')
% spatial
[nrow,ncol] = size(imGreen);
[Cols,Rows] = meshgrid(1:ncol,1:nrow);
lowerRegion = imGreen;
lowerRegion(lowerRegion < 200) = 0;
lowerRegion(lowerRegion > 0) = 1;
L = bwlabel(lowerRegion);
% can logically evaluate a histcounts of L to determine thresholds
lowerLCol1 = min(Cols(L == 2));
lowerLCol2 = max(Cols(L == 2));
lowerLRow1 = min(Rows(L == 2));
lowerLRow2 = max(Rows(L == 2));
imLowerL = imdata(lowerLRow1:lowerLRow2,lowerLCol1:lowerLCol2,:);
lowerRCol1 = min(Cols(L == 4));
lowerRCol2 = max(Cols(L == 4));
lowerRRow1 = min(Rows(L == 4));
lowerRRow2 = max(Rows(L == 4));
imLowerR = imdata(lowerRRow1:lowerRRow2,lowerRCol1:lowerRCol2,:);
topRegion = 1 - lowerRegion;
topRegion = imopen(topRegion,ones(7,1));
topRegion = imopen(topRegion,ones(1,7));
topCol1 = min(Cols(topRegion > 0));
topCol2 = max(Cols(topRegion > 0));
topRow1 = min(Rows(topRegion == 1));
topRow2 = max(Rows(topRegion == 1));
imTop = imdata(topRow1:topRow2,topCol1:topCol2,:);
figure()
subplot(2,2,1);
imagesc(imTop);
axis off; axis equal;
title('Top Image');
subplot(2,2,2);
imagesc(imLowerL);
axis off; axis equal;
title('Lower Left Image');
subplot(2,2,3);
imagesc(imLowerR);
axis off; axis equal;
title('Lower Right Image');
subplot(2,2,4);
imagesc(L);
axis off; axis equal;
title('Color Coded Regions');
by color component
by spatial
  댓글 수: 2
Image Analyst
Image Analyst 2022년 1월 2일
His later comments were that what he really wanted was to split the lower panels into individual characters. You can do this by taking the horizontal profile:
horizontalProfile = sum(mask, 1);
and then thresholding that to find columns that have some black in them or are all white.
Meg Noah
Meg Noah 2022년 1월 2일
Continuing with the previous script:
% getting the text
tmp = imGreen(lowerLRow1:lowerLRow2,lowerLCol1:lowerLCol2,:);
tmp(tmp < 190) = 0;
tmp(tmp > 0) = 1;
% invert
tmp = 1 - tmp;
% remove border artifacts
tmp(1,:) = 0;
tmp(:,1) = 0;
tmp(end,:) = 0;
tmp(:,end) = 0;
% close to get full font
tmp = imclose(tmp,ones(5,5));
% blob color
LL = bwlabel(tmp);
[nr,nc] = size(LL);
[Cols,Rows] = meshgrid(1:nc,1:nr);
LLCol1 = min(Cols(LL == 1));
LLCol2 = max(Cols(LL == 1));
LLRow1 = min(Rows(LL == 1));
LLRow2 = max(Rows(LL == 1));
imFont1 = imLowerL(LLRow1:LLRow2,LLCol1:LLCol2,:);
LLCol1 = min(Cols(LL == 2));
LLCol2 = max(Cols(LL == 2));
LLRow1 = min(Rows(LL == 2));
LLRow2 = max(Rows(LL == 2));
imFont2 = imLowerL(LLRow1:LLRow2,LLCol1:LLCol2,:);
LLCol1 = min(Cols(LL == 3));
LLCol2 = max(Cols(LL == 3));
LLRow1 = min(Rows(LL == 3));
LLRow2 = max(Rows(LL == 3));
imFont3 = imLowerL(LLRow1:LLRow2,LLCol1:LLCol2,:);
figure()
subplot(2,2,1)
imagesc(LL);
axis off; axis equal;
subplot(2,2,2)
imagesc(imFont1);
axis off; axis equal;
subplot(2,2,3)
imagesc(imFont2);
axis off; axis equal;
subplot(2,2,4)
imagesc(imFont3);
axis off; axis equal;
tmp = imGreen(lowerRRow1:lowerRRow2,lowerRCol1:lowerRCol2,:);
tmp(tmp < 190) = 0;
tmp(tmp > 0) = 1;
% invert
tmp = 1 - tmp;
% remove border artifacts
tmp(1,:) = 0;
tmp(:,1) = 0;
tmp(end,:) = 0;
tmp(:,end) = 0;
% close to get full font
tmp = imclose(tmp,ones(5,5));
% blob color
LR = bwlabel(tmp);
[nr,nc] = size(LR);
[Cols,Rows] = meshgrid(1:nc,1:nr);
LRCol1 = min(Cols(LR == 1));
LRCol2 = max(Cols(LR == 1));
LRRow1 = min(Rows(LR == 1));
LRRow2 = max(Rows(LR == 1));
imFont1 = imLowerR(LRRow1:LRRow2,LRCol1:LRCol2,:);
LRCol1 = min(Cols(LR == 2));
LRCol2 = max(Cols(LR == 2));
LRRow1 = min(Rows(LR == 2));
LRRow2 = max(Rows(LR == 2));
imFont2 = imLowerR(LRRow1:LRRow2,LRCol1:LRCol2,:);
LRCol1 = min(Cols(LR == 3));
LRCol2 = max(Cols(LR == 3));
LRRow1 = min(Rows(LR == 3));
LRRow2 = max(Rows(LR == 3));
imFont3 = imLowerR(LRRow1:LRRow2,LRCol1:LRCol2,:);
figure()
subplot(2,2,1)
imagesc(LR);
axis off; axis equal;
subplot(2,2,2)
imagesc(imFont1);
axis off; axis equal;
subplot(2,2,3)
imagesc(imFont2);
axis off; axis equal;
subplot(2,2,4)
imagesc(imFont3);
axis off; axis equal;

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by