how to transfer image pixel values into array
6 views (last 30 days)
Show older comments
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 Comment
David Young
on 20 Feb 2014
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?
Accepted Answer
Image Analyst
on 20 Feb 2014
Edited: Image Analyst
on 20 Feb 2014
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 Comments
Image Analyst
on 20 Feb 2014
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
Image Analyst
on 20 Feb 2014
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.
More Answers (1)
Adam
on 20 Feb 2014
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
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!