Hi Basma
1.-
In order to split the image as requested there's no need to convert the image to greyscale.
The key is to spot the white gap between both images.
2.-
Acquiring image
clear all;close all;clc
A=imread('001.jpg');
figure(1);imshow(A)
[sz1 sz2 sz3]=size(A)
sz1 =
754
sz2 =
1148
sz3 =
3
Only along the split area all pixels are white meaning that only there the sum is about
.
It's a bit less because not all gap pixels are 255 white, but their values are the closest ones to the top value 255.
.
.
3.-
The following calculates the sum of all pixels column by column.
L=zeros(1,sz2);
for k=1:1:sz2
L(k)=sum(A(:,k,1)+A(:,k,2)+A(:,k,3));
end
L=L/1e5;
figure(2);plot(L);grid on
[rows,cols]=find(L(L>1.9))
hold on
stem(cols,ones(1,numel(cols)),'g')
.
.
4.-
The gap to split the image is the middle one
nrange=[1:1:sz2]
n1=nonzeros(nrange.*(L>1.9))
n1 =
1
2
3
4
5
6
568
569
570
571
572
573
574
575
576
1141
1142
1143
1144
1145
1146
1147
1148
A way to get right the mid point of the split gap is with command kmeans.
.
n2=kmeans(n1,3)
n2 =
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
3
3
3
3
3
3
3
3
n3=find(n2==1)
n_split=n1(floor(.5*(min(n3)+max(n3))))
n_split =
572
5.-
Now you can cut:
Aleft=A(:,[1:n_split],:);
Aright=A(:,[n_split+1:end],:);
6.-
Saving each part
imwrite(Aleft,'name_image_left.jpg')
imwrite(Aright,'name_image_right.jpg')
.
Basma
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance for time and attention
John BG