getting pixels information of the image
    8 views (last 30 days)
  
       Show older comments
    
Hii guys..
I want to get the pixels information of a black and white image in 8 bit binary format. 
what is the best way to do that?
1 Comment
  Geoff Hayes
      
      
 on 5 Apr 2020
				Divya - please clarify with an example of what you are looking for. Do you have a mxn image of unsigned integers? Are the integers already 8-bit? Do you want to write out (to text file) or put in a cell array the 8-bit binary strings for each pixel?
Answers (2)
  Harshendra Shah
      
 on 9 Apr 2020
        Hi Divya,
You can use impixel function to determine the values of one or more pixels in an image and return the values in a variable.
After getting the pixel values you can convert those values into 8-bit binary vector by using de2bi function.
You can refer to the following MATLAB Answers for better understanding: 
I hope this helps.
0 Comments
  Image Analyst
      
      
 on 9 Apr 2020
        Try this.  Adapt as needed.
% Create some sample data - a small image.
grayImage = uint8(10*magic(5))
[rows, columns] = size(grayImage)
% Loop over all locations giving the gray level in decimal and binary.
for col = 1 : columns
	for row = 1 : rows
		thisGrayLevel = grayImage(row, col);
		binaryString = dec2bin(thisGrayLevel);
		fprintf('grayImage(%d, %d) = %d = "%s".\n', ...
			row, col, thisGrayLevel, binaryString);
	end
end
You'll see
grayImage =
  5×5 uint8 matrix
   170   240    10    80   150
   230    50    70   140   160
    40    60   130   200   220
   100   120   190   210    30
   110   180   250    20    90
rows =
     5
columns =
     5
grayImage(1, 1) = 170 = "10101010".
grayImage(2, 1) = 230 = "11100110".
grayImage(3, 1) = 40 = "101000".
grayImage(4, 1) = 100 = "1100100".
grayImage(5, 1) = 110 = "1101110".
grayImage(1, 2) = 240 = "11110000".
grayImage(2, 2) = 50 = "110010".
grayImage(3, 2) = 60 = "111100".
grayImage(4, 2) = 120 = "1111000".
grayImage(5, 2) = 180 = "10110100".
grayImage(1, 3) = 10 = "1010".
grayImage(2, 3) = 70 = "1000110".
grayImage(3, 3) = 130 = "10000010".
grayImage(4, 3) = 190 = "10111110".
grayImage(5, 3) = 250 = "11111010".
grayImage(1, 4) = 80 = "1010000".
grayImage(2, 4) = 140 = "10001100".
grayImage(3, 4) = 200 = "11001000".
grayImage(4, 4) = 210 = "11010010".
grayImage(5, 4) = 20 = "10100".
grayImage(1, 5) = 150 = "10010110".
grayImage(2, 5) = 160 = "10100000".
grayImage(3, 5) = 220 = "11011100".
grayImage(4, 5) = 30 = "11110".
grayImage(5, 5) = 90 = "1011010".
0 Comments
See Also
Categories
				Find more on Convert Image Type in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


