Original image size 769*770, I am geting error as dimension mismatch

조회 수: 1 (최근 30일)
vetri veeran
vetri veeran 2014년 11월 24일
답변: Jan 2014년 11월 24일
Original image size 769*770
org_im=imread('picture1.jpg');
[rows,columns,numberofcolorbands]=size(org_im)
if numberofcolorbands >1 org_im=org_im(:,:,2); end
org_im=im2double(org_im);
figure(1); imshow(org_im);title('Original Image')
f=zeros(771,772); [m,n]=size(f); f(769,770)=size(org_im);
I am getting an error as,
Subscripted assignment dimension mismatch.
Error in sobelmaskspat_d (line 23) f(769,770)=size(org_im);
How to overcome this,
please help me.
Thank you

채택된 답변

Jan
Jan 2014년 11월 24일
f(769,770) = size(org_im);
The right hand side replies a vector, but the left hand side is one element of a matrix, a scalar. We cannot guess what this line should do. So please explain this detail.
If you want to pad a matrix by zeros:
f = zeros(771,772);
f(2:770, 2:771) = org_im;

추가 답변 (1개)

Guillaume
Guillaume 2014년 11월 24일
What are you trying to do with that line anyway?
size(org_im) is at least a 1x2 array, possibly a 1x3 array if you have colour channels. You're trying to store that array in the single element at (769, 770) of f. Since you can only put one value there, it's never going to work.
  댓글 수: 2
vetri veeran
vetri veeran 2014년 11월 24일
my original image size is 769*770
I created an array with zeros as
f=zeros(771,772);
In the newly created zero padded array ie) in 771*772, I want to place image 769*770.
How can i achieve this.
Thank you
Guillaume
Guillaume 2014년 11월 24일
f = zeros(size(org_im) + 2); %no need to hardcode the size
f(2:end-1, 2:end-1) = org_im;
Or, if you have the image processing toolbox, use padarray
f = padarray(org_im, [1 1]);

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by