Unable to perform assignment because the left and right sides have a different number of elements.

2 visualizaciones (últimos 30 días)
I am attempting to swap the pixels of the brightest with the darkest in the image. I get this error but as far as I know they have the same number of elements. I check with numel.
  1 comentario
Jan
Jan el 19 de Nov. de 2022
If you post code as formatted text, it can be used to create an answer using copy&paste. Screenshots are less useful.

Iniciar sesión para comentar.

Respuestas (2)

the cyclist
the cyclist el 19 de Nov. de 2022
The assignment will only have the same number of elements if maskMax3D and maskMin3D have the same number of TRUE elements. For example, with smaller matrices, so that we can see what is going on:
% Note that these masks do not have the same number of TRUE elements
mask1 = logical([1 1; 1 0]);
mask2 = logical([1 0; 0 1]);
M1 = [2 3; 5 7];
M2 = [11 13; 17 19];
% Therefore these two arrays do not have the same number of elements, and
% cannot be assigned to each other
M1(mask1)
ans = 3×1
2 5 3
M2(mask2)
ans = 2×1
11 19

Image Analyst
Image Analyst el 24 de Nov. de 2022
Not sure what you mean because your question is not complete (no code, no images, no good explanation). Maybe it's this
yourImage = 255 - yourImage;
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by