how to transfer image pixel values into array

조회 수: 7 (최근 30일)
sonam s
sonam s 2014년 2월 20일
댓글: Image Analyst 2014년 2월 20일
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
David Young
David Young 2014년 2월 20일
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?

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

채택된 답변

Image Analyst
Image Analyst 2014년 2월 20일
편집: Image Analyst 2014년 2월 20일
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
Image Analyst
Image Analyst 2014년 2월 20일
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
Image Analyst 2014년 2월 20일
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개)

Adam
Adam 2014년 2월 20일
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
sonam s
sonam s 2014년 2월 20일
THANKS FOR YOUR HELP
I HAVE GIVEN THE ALGORITHM BELOW
PLEASE HELP ME HOW TO IMPLEMENT THIS
sonam s
sonam s 2014년 2월 20일
THE BELOW ALGORITHM IS FOR PIXEL PERMUTATION

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by