how to transfer image pixel values into array

transfer image pixel values into array for complete image
  • array(,1)=R value
  • array(,2)=G value
  • array(,3)=B value
  • array(,4)=x position
  • array(,5)= y position

1 个评论

The question does not make sense. array(,1) is not valid syntax - there needs to be something in front of the comma. Also, what are you transferring the values from?

请先登录,再进行评论。

 采纳的回答

Try this:
for k = 1 : length(RValues)
array(k, 1) = RValues(k);
array(k, 2) = GValues(k);
array(k, 3) = BValues(k);
array(k, 4) = XValues(k);
array(k, 5) = YValues(k);
end
OR
% For a complete image
k = 1;
[rows, columns, numberOfColorChannels) = size(rgbImage);
if numberOfColorChannels == 3
for col = 1 : columns
for row = 1 : rows
array(k, 1) = rgbImage(row, col, 1);
array(k, 2) = rgbImage(row, col, 2);
array(k, 3) = rgbImage(row, col, 3);
array(k, 4) = col;
array(k, 5) = row;
k = k + 1;
end
end
end
I don't know why you'd ever want this unless maybe you were exporting to some kind of modeling/cadcae program.

2 个评论

sonam's "Answer" moved here, since it was not an answer.
1Start
2.img = input plain image.
3 rows, cols = size of img.
4 create array of (rows*cols , 5)
5 transfer img pixel values into array for complete image
array(,1)=R value
array(,2)=G value
array(,3)=B value
array(,4)=x position
array(,5)= y position
6 sort this array
7 img = form an image using this array
8 Invoke ImageEncryption(img, rows, cols)
9 End
I did 1-5 for you. To sort you just call the sort() function but I don't know what column you are sorting on. And 7 is unnecessary since you already have the image - you needed it to do steps 2-5. Only you know what you need to do for step 8.

请先登录,再进行评论。

更多回答(1 个)

If you mean array(:,1) = R value, then:
if true
myImage = imread('myFile.img');
array(:,1) = reshape(myImage(:,:,1),[],1); %red
array(:,2) = reshape(myImage(:,:,2),[],1); %green
array(:,3) = reshape(myImage(:,:,3),[],1); %blue
[array(:,4),array(:,5)] = ind2sub(size(myImage(:,:,1)),1:numel(myImage(:,:,1)));
end

2 个评论

THANKS FOR YOUR HELP
I HAVE GIVEN THE ALGORITHM BELOW
PLEASE HELP ME HOW TO IMPLEMENT THIS
THE BELOW ALGORITHM IS FOR PIXEL PERMUTATION

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by