im trying to add an image to a matrix of ones for which i have used the following code:
c=imread('C:\Users\Richik\Desktop\ima.png');
[x,y]=size(c)
m=ones(x,y);
g=m+c;
but even when the matrix dimensions are same,im getting this error:
??? Error using ==> plus
Matrix dimensions must agree.
i cant figure out why this is happening.....

 채택된 답변

Walter Roberson
Walter Roberson 2015년 10월 12일

0 개 추천

Chances are that your PNG image is an RGB image and so is 3 dimensional. You should look at
s = size(c)
[x,y] = size(c)
and I think you will find that y is not equal to s(2). Read the documentation for size() to understand why not.

댓글 수: 4

Terry McGinnis
Terry McGinnis 2015년 10월 12일
편집: Walter Roberson 2015년 10월 12일
[x,y]=size(c)
m=ones(x,y);
[u,v]=size(m)
i get this:
x =
512
y =
1536
u =
512
v =
1536
and after using rgb2gray() and then calculating the size i get:
x =
512
y =
512
u =
512
v =
512
yet when i'm doing this operation:
e=c+m;
subplot(3,3,3);
imshow(e);
title('addition');
i'm getting a fully white image. shouldnt the output be a little brighter version of the original image?
Walter Roberson
Walter Roberson 2015년 10월 12일
[d1,d2,d3,...,dn] = size(X), for n > 1, returns the sizes of the dimensions of the array X in the variables d1,d2,d3,...,dn, provided the number of output arguments n equals ndims(X). If n does not equal ndims(X), the following exceptions hold:
n < ndims(X) di equals the size of the ith dimension of X for 0<i<n, but dn equals the product of the sizes of the remaining dimensions of X, that is, dimensions n through ndims(X).
A change of 1/256 in the brightness of an image is not necessarily going to be very noticeable, especially if you have not used a full 256 entry colormap
colormap(gray(256))
Terry McGinnis
Terry McGinnis 2015년 10월 12일
thank u

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

추가 답변 (1개)

Eng. Fredius Magige
Eng. Fredius Magige 2015년 10월 12일

0 개 추천

Hi It has to follow its rule, and might be g=[m,c];

댓글 수: 1

Walter Roberson
Walter Roberson 2015년 10월 12일
That would, if it worked, append c after m, not add 1 to each element of c.

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

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

질문:

2015년 10월 12일

댓글:

2015년 10월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by