필터 지우기
필터 지우기

How do I fix a "Subscripted assignment dimension mismatch."

조회 수: 4 (최근 30일)
amitesh kumar
amitesh kumar 2011년 2월 2일
clc
c=1;
t=1;
% To read in the watermarked image
[watermarked_image cmap]=imread('lsb_image.bmp');
watermarked_image=double(watermarked_image);
% To measure the size of the watermarked_image
watermarked_image_size=size(watermarked_image);
x=watermarked_image_size(1);
y=watermarked_image_size(2);
z=watermarked_image_size(1);
% To convert the watermarked image from a MxN matrix into a row
for a=1:watermarked_image_size(1,1)
watermarked_image_row(1,c:z)=watermarked_image(a,1:y);
c=c+y;
z=z+y;
end
When I run it I get the following error:
??? Subscripted assignment dimension mismatch.
Error in ==> single_decode at 15
watermarked_image_row(1,c:z)=watermarked_image(a,1:y);
Can anybody help me remove this error? I am using a test image of size 256*256 and lsb_image.bmp of 12*9.

답변 (3개)

Jan
Jan 2011년 2월 2일
There is no need to use a complicated FOR loop to get a matrix as row vector:
[watermarked, cmap] = imread('lsb_image.bmp');
watermarked = double(watermarked);
watermarked_row = reshape(transpose(watermarked), 1, numel(watermarked));
EDITED: And together with Sean de's addition: If you image is a [Width x Height x 3] 3D array, convert it to a grey scale at first:
watermarked = rgb2gray(watermarked);
Or operate on a single color channel only, e.g. red:
watermarked = rgb2gray(:, :, 1);

amitesh kumar
amitesh kumar 2011년 2월 2일
%This program decode the watermark from the single embed watermarked image clc c=1; t=1; %To read in the watermarked image [watermarked_image cmap]=imread('lsb_image.bmp'); watermarked_image=double(watermarked_image); %To measure the size of the watermarked_image watermarked_image_size=size(watermarked_image); x=watermarked_image_size(1); z=watermarked_image_size(1); y=watermarked_image_size(2); %To convert the watermarked image from a MxN matrix into a row
[watermarked, cmap] = imread('lsb_image.bmp'); watermarked = double(watermarked); watermarked_row = reshape(transpose(watermarked), 1, numel(watermarked));
if i am directly replacing your code with previous one by removing for loop, than i am getting following error
??? Error using ==> transpose Transpose on ND array is not defined.
Error in ==> single_decode at 16 watermarked_row = reshape(transpose(watermarked), 1, numel(watermarked));
have u any idea how to remove this error..and y this error is occurring. plz help me
  댓글 수: 1
Doug Hull
Doug Hull 2011년 2월 2일
please add this as a comment to the original question or an answer. It should not be an answer by itself. You can delete it after moving it.

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


Sean de Wolski
Sean de Wolski 2011년 2월 2일
probably have to do:
watermarked_image = rgb2gray(watermarked_image);
then Jan's reshape call
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 2월 6일
After the imread() statement, put in
disp(ndims(watermarked))
and tell us what it reports.
Why are you reading the same image twice? Once into watermarked_image and once into watermarked ?
Jan
Jan 2011년 2월 6일
There are 2 kinds of gray scale images: 1. just the colors are gray, but they are saved as RGB values, 2. the JPEG has a gray scale "color" table and used index colors. As Walter suggested, you can distinguish them by inspecting the reply of IMREAD.

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

카테고리

Help CenterFile Exchange에서 Matrix Operations and Transformations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by