- What is the result of size(im) ?
- When you say you want to "add these values to the image" do you mean you want to concatenate them (as mentioned in your title) and if so, where should that vector be inserted?
concatenating arrays and matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Matpar
el 16 de Ag. de 2019
Comentada: Matpar
el 17 de Ag. de 2019
Hi all I trying to get a simple syntax to add this constant to image values
im=imread(im)
im=rgb2gray(im)
so now that im is now the gray scale image
i am try to add these values to the image
C1=[10,20,50,100]
Can profesional provide an example of how this is done in the simplest form using a for loop?
thank you in advance!!!
7 comentarios
Adam Danz
el 16 de Ag. de 2019
Editada: Adam Danz
el 16 de Ag. de 2019
If your array is 5 x 5 you cannot concatenate a vector with only 4 elements!
Concatenation involves joining two arrays. Here are two examples.
% Horizontal concatenation
A = [1 2 3;
4 5 6];
B = [11 12 13;
14 15 16];
C = [A,B]
C =
1 2 3 11 12 13
4 5 6 14 15 16
% Vertical concatenation
C = [A; B]
C =
1 2 3
4 5 6
11 12 13
14 15 16
Notice that the size of A and B are equal in the dimensions being concatenated. Here's an example that would FAIL.
X = [1 2 3];
Y = [1 2 3 4];
Z = [X,Y]; % This works
Z2 = [X; Y]; % This doesn't work!
To learn more:
Respuesta aceptada
Walter Roberson
el 16 de Ag. de 2019
Borrow my code from your previous question https://www.mathworks.com/matlabcentral/answers/475006-threshold-multiple-values-at-the-same-time which had
nd = ndims(YourImageArray);
Thresholded_arrays = bsxfun(@le, YourImageArray, reshape([50, 100, 150, 200], [ones(1,nd), 4]) );
Instead of @le you would use @plus
nd = ndims(YourImageArray);
Incremented_arrays = bsxfun(@plus, YourImageArray, reshape(uint8([50, 100, 150, 200]), [ones(1,nd), 4]) );
5 comentarios
Walter Roberson
el 17 de Ag. de 2019
C1 = [10,20,50,100];
numC1 = length(C1);
imrgb = imread(FILENAME);
imgray = rgb2gray(imrgb);
[r, c] = size(imgray);
output = zeros(r, c, numC1, class(imgray)); %probably it will be uint8
for C1idx = 1 : numC1
this_C1 = C1(C1idx);
output(:,:,C1idx) = imgray + this_C1;
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!