How to round (or convert) an array to integer?

I need to first convert multiple images to an array of intensity value and then do some calculations. I need to round up each intensity in the array first before the calculations. I tried just I1_int = round(I1_int); but it did not work as "Undefined function 'round' for input arguments of type 'struct'." Any idea would be greatly appreciated! Thank you! Here is a portion of my code.
I1_int = regionprops(M, I1, 'MeanIntensity', 'Centroid'); %Intensities of first frame
if length(I)>1
I2_int = regionprops(M, I2, 'MeanIntensity', 'Centroid'); %Intensities of last frame
Final = cell2mat({I2_int(:).MeanIntensity});
Initial = cell2mat({I1_int(:).MeanIntensity});
Percent = 100*[(Final - I2_BG) - (Initial - I1_BG)]./ (Initial- I1_BG)

 Respuesta aceptada

Image Analyst
Image Analyst el 15 de Nov. de 2016
You need to call ceil() on the mean intensities, not on the measurement structure itself. Try this:
props = regionprops(M, I1, 'MeanIntensity', 'Centroid'); %Intensities of first frame
% Extract the mean intensities by themselves into a new array.
meanIntensities = [props.MeanIntensity];
% Round up to nearest integer.
I1_int = ceil(meanIntensities);

4 comentarios

Thanks for the suggestion! In such case, when I put in my codes after your suggestion.
props1 = regionprops(M, I1, 'MeanIntensity', 'Centroid');
meanIntensities1 = [props1.MeanIntensity];
I1_int = ceil(meanIntensities);
Initial = cell2mat({I1_int(:).MeanIntensity});
Then it becomes improper index matrix reference because of cell2mat. Does cell2mat become removable? I removed it and it ran without error but I can't tell if all the numbers are correct.
Walter Roberson
Walter Roberson el 15 de Nov. de 2016
I1_int would already be a numeric array and would not need to be converted using cell2mat
Image Analyst
Image Analyst el 15 de Nov. de 2016
Walter's right. Did you even inspect what I1_int is in the workspace before you did the cell2mat() line? If you had you would have seen that I1_int is already a double vector, not a structure, so doing this I1_int(:).MeanIntensity would have thrown an error. Again, there's no need to do that. Don't over-complicate it!!
B Duan
B Duan el 15 de Nov. de 2016
Yes, indeed I1_int is a double vector and round to the nearest integer. Thank you so much guys.

Iniciar sesión para comentar.

Más respuestas (1)

Daniel kiracofe
Daniel kiracofe el 15 de Nov. de 2016

1 voto

ceil() should work to round up to the nearest integer

Categorías

Preguntada:

el 15 de Nov. de 2016

Comentada:

el 15 de Nov. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by