After obtaining the pixel values of an image..how to store those pixel values in an array?

After obtaining the pixel values of an image..how to store those pixel values in an array?

댓글 수: 4

how are you obtaining pixel values ?
clc;
close all;
my_image =imread('football.jpg');
figure,imshow(my_image);title('Orginal Image In Colour');
my_image=rgb2gray(my_image);
figure,imshow(my_image);title('Orginal Image In Gray scale');
% my_image = imresize(my_image,[512 512]); if you want to fix image size as constant
[rows,columns,depth]=size(my_image); % Here row and columns of particular image are fetched
for R=1:rows
for C=1:columns
pixel=my_image(R,C);
disp (R)
end
end
If this isnt correct please say that method also along with how to load them in an array?
thanks in advance.
Kamali, you have to explain better what it is you want to do. As commented you already have the pixels in an array. It's the my_image array

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

 채택된 답변

pixel = cell(1,rows);
ctr = 1;
for R=1:rows
for C=1:columns
pixel{ctr}=my_image(R,C);
disp (R)
end
ctr = ctr+1;
end
celldisp(pixel)
[pixel{:}] % double array

댓글 수: 6

pixel{ctr}( C) = ...
otherwise you overwrite .
The whole question is very puzzling and this answer is just as much puzzling. As per Walter's answer, the pixels are already stored in an array: my_image.
All the above code does is very inefficiently copy only the red channel of the image array into a cell array. The same could be achieved much faster in just one line with:
pixel = num2cell(my_image(:, :, 1));
which is a complete waste of time and just use more memory to store the same information.
Thank you Guillaume , you are completely right , just noticed after answering the my_image was already stored.
ACTUALLY my input is a 256X320 but i get only a single row with 256 elements in it.
my_image =imread('football.jpg');
my_image=rgb2gray(my_image);
[rows,columns,depth]=size(my_image);
pixel = cell(1,rows);
ctr = 1;
for R=1:rows
for C=1:columns
pixel{ctr}=my_image(R,C);
end
ctr = ctr+1;
end
celldisp(pixel)
disp ([pixel{:}]); % double array
what are the necessary changes in it?
thanks in advance.
@kamali see sir Walter's answer this is not the correct approach as mentioned by the peers.

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

추가 답변 (3개)

Walter Roberson
Walter Roberson 2018년 12월 18일
The pixel values are already stored in my_image and do not need to be stored again .
Kamali M
Kamali M 2018년 12월 18일
@madhan sir, please tell me what should i change i dont get it..
thank u sir.

댓글 수: 1

What data type do you need as output? What array size do you need as output? What difference do you intend between "pixel values" that you want stored, compared to what is already in my_array ?

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

Saipraveen
Saipraveen 2019년 9월 30일
For the information of other users, In this file exchange - https://www.mathworks.com/matlabcentral/fileexchange/72535-image-to-c-c-array-converter, I have written a script to generate an array from an image. I convert the input image to monochrome and store the pixel values in hex format in a different file. It could be modified to suit your needs.
Hope that helps.

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

질문:

2018년 12월 18일

답변:

2019년 9월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by