Problem working with 3-D image matrix

3 visualizaciones (últimos 30 días)
Mardhika Jenned
Mardhika Jenned el 4 de Mzo. de 2011
I want to create an image is divided into 3 parts automatically with different levels of light, but this script does not work for an image that has a decimal value after a divided three-dimensional, why ?
this is my script.
g=input('input picture name(ex : xxxx.jpg or xxxx.gif"): ','s');
start=imread(g);
s=size(start);
z=s(1,1);
a=z/3;
y=ceil(a);
x=y+1;
b=y*2;
c=y*3;
start([1:y],:,:)=uint8(double(start([1:y],:,:))*4);
start([y:b],:,:)=uint8(double(start([y:b],:,:))*1);
start([b:c],:,:)=uint8(double(start([b:c],:,:))*0);
image(start);
error says
??? Index exceeds matrix dimensions.
Error in ==> kaka at 12
start([b:c],:,:)=uint8(double(start([b:c],:,:))*0);

Respuesta aceptada

Brett Shoelson
Brett Shoelson el 4 de Mzo. de 2011
I'm not sure what you mean by "does not work for an image that has a decimal value after a divided three-dimensional."
But I think that you're trying to do something like this:
start = imread(g);
base = ones(ceil(size(start,1)/3),size(start,2),size(start,3));
base = uint8(cat(1,base*4,base,base*0));
start = start.*base;
Cheers, Brett
  1 comentario
Mardhika Jenned
Mardhika Jenned el 4 de Mzo. de 2011
please use the formula for a beginner like I use, because I do not understand the formula you provide. .
your formula is doesn't work for picture it has vertical size decimal,
example: vertical size is 101
100 /3 = 33.33333333 <<< the program is error
please help me !

Iniciar sesión para comentar.

Más respuestas (2)

Brett Shoelson
Brett Shoelson el 4 de Mzo. de 2011
Well, if you want to chop your image into thirds and it doesn't divide equally into three bins, then YOU have to decide how to chop it. CEIL, ROUND, FLOOR, FIX...all convert fractions to whole numbers.
If you want to ensure that your matrix dimensions match, thry this:
start = imread(g);
base = ones(ceil(size(start,1)/3),size(start,2),size(start,3));
base = uint8(cat(1,base*4,base,base*0));
base = base(1:size(start,1),:,:);
start = start.*base;
So, I first built a matrix of ones 1/3 the size of start. Then I concatenated (CAT) three copies of it, once multiplied by 4, once multiplied by 1, and once multiplied by zero. That will either be exactly the same size as start, or 1 or 2 rows longer than start. So next, I "cropped" (base = base(1:size(start,1),:,:);) the result to be the same size as start, and then multiplied the two matrices element-by-element.
Cheers, Brett
  2 comentarios
Mardhika Jenned
Mardhika Jenned el 4 de Mzo. de 2011
can you use the matriks logic to solve this problem ? thx
Walter Roberson
Walter Roberson el 4 de Mzo. de 2011
What do you include in "matrix logic" ?
If you mean something like matrix multiplication, then NO. Brett's code will expand the matrix by up to two rows, but matrix multiplication cannot change the number of rows in a matrix.

Iniciar sesión para comentar.


Brett Shoelson
Brett Shoelson el 5 de Mzo. de 2011
Here's another approach, just for fun:
start = imread(g);
multCol = reshape(repmat([4 1 0],ceil(size(start,1)/3),1),[],1);
multCol = uint8(multCol(1:size(start,1),:));
start = bsxfun(@times,start,multCol);
Have a good weekend!
Brett
  1 comentario
Brett Shoelson
Brett Shoelson el 5 de Mzo. de 2011
Or, more generally, change that second "multCol=" line to:
multCol = cast(multCol(1:size(start,1),:),class(start));
Walter's right, of course, that your matrix multiplications have to make mathematical sense, dimensionally speaking. For element-wise multiplications (.*), for instance, the matrices have to be the same size. But if the matrices you are attempting to multiply differ dimensionally in such a way that expanding singleton dimensions can make the matrices dimensionally consistent, the underused BSXFUN allows you to play fast and loose with your matrices! :)
Cheers,
Brett

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by