To divide an image into 2 equal halves

27 ビュー (過去 30 日間)
keerthi
keerthi 2012 年 9 月 26 日
コメント済み: mariena aloor 2019 年 9 月 10 日
I wrote the code for it . I can divide the left side of an image and while doing for the right side left part of it is black and right part is the second half of the image . The problem where i am facing is , in the 2nd for loop it starts with k=1 n m=110 so for others column values from 1 to 109 as a default its taking zero. How to sort out this problem.
% code
x=imread('img1.jpg');
image=rgb2gray(x);
[q r]=size(image);
s=r/2;
for i=1:q
for j=1:s
n1(i,j)=image(i,j);
end
end
for k=1:q
for m=s:r
n2(k,m)=image(k,m);
end
end
imshow(n1)
figure
imshow(n2)
end
  4 件のコメント
Durgesh Naik
Durgesh Naik 2015 年 4 月 3 日
till not working
Image Analyst
Image Analyst 2015 年 4 月 3 日
How do you know? Did you ask keerthi? He accepted the answer so I would assume that it is working.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2012 年 9 月 26 日
n1 = image(:, 1 : end/2);
n2 = image(:, end/2+1 : end );
  4 件のコメント
Image Analyst
Image Analyst 2013 年 10 月 12 日
編集済み: Image Analyst 2013 年 10 月 13 日
Well . . . what is the name of your variable? I really really doubt it's called image - at least it shouldn't be. So you need to use the actual name of your image array variable. What is it? Let's say it's called grayImage. Then use grayImage(....) instead of image(....)
Jaya Darshini N K
Jaya Darshini N K 2019 年 2 月 11 日
i have tried this and this is working perfectly. but images ni and n2 are displaying along with the full image. i want only n1 and n2 to be displayed.
thanks in advance!!!

サインインしてコメントする。

その他の回答 (2 件)

Jay Li
Jay Li 2018 年 5 月 10 日
function y = halfpic(x)
% Enter an image in matrix form
n = floor(size(x)/2)
m = size(x);
Lpic = x(:,1:n(2),:);
Rpic = x(:,n(2)+1:m(2),:);
imshow(Lpic);
figure
imshow(Rpic);
  1 件のコメント
mariena aloor
mariena aloor 2019 年 9 月 10 日
How to divide an image in to 8 regions

サインインしてコメントする。


JEBA CHRISTILDA
JEBA CHRISTILDA 2016 年 8 月 9 日
yes i too tried this but it is showing error in imshow(n1)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by