how to split image to 3 parts

8 Ansichten (letzte 30 Tage)
amr elslene
amr elslene am 30 Dez. 2021
Kommentiert: Meg Noah am 2 Jan. 2022

Akzeptierte Antwort

Image Analyst
Image Analyst am 30 Dez. 2021
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 Kommentare
amr elslene
amr elslene am 31 Dez. 2021
Bearbeitet: amr elslene am 31 Dez. 2021
all i need is take like that
from plat like that
Thanks in advance @Image Analyst
Image Analyst
Image Analyst am 31 Dez. 2021
@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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Meg Noah
Meg Noah am 2 Jan. 2022
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 Kommentare
Image Analyst
Image Analyst am 2 Jan. 2022
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 am 2 Jan. 2022
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;

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by