how can we represent a pixel to a character in image ?

1 view (last 30 days)
Write a MATLAB script that allows reading an image file.
1. Convert color image to gray scale and display dot matrix
Image has a value from 0 to 1 (can be divided into 10 levels depending on the color scale
want to display)
2. Reduce the resolution of the current image to 64x64 pixels.
3. For each gray scale, insert the corresponding numeric character
alphabet letters.

Answers (2)

DGM
DGM on 24 Sep 2023
Edited: DGM on 24 Sep 2023
To convert to unit-scale:
im2double() normalizes the image with respect to black and white
mat2gray() normalizes the image with respect to its extrema
To quantize the image:
rgb2ind() for RGB inputs
gray2ind() for gray inputs
or ...
multithresh() used with imquantize()
imquantize() quantize using specified input and output level lists
You can specify the output values in the call to imquantize(), so if you planned ahead, you should then just be able to cast the output of imquantize() using char(). Mutithresh() could be replaced with a simple linear sequence, but this is convenient and likely sufficient.
% ... assuming everything has been prepared ...
nlevels = 10;
inlevels = multithresh(inpict,nlevels); % get input levels
outlevels = double('A') + (0:nlevels); % some set of characters (represented in double)
outpict = imquantize(inpict,inlevels,outlevels); % quantize
outpict = char(outpict) % cast output values back to char
If you ask me, the assignment is vague and leads the student to approach the task using a counterproductive order of operations. You would preferably quantize after resizing, not before. If you resize your quantized image using imresize() defaults, it won't retain the same number of levels. You would have to specify nearest-neighbor interpolation if you did.
I also don't think it's very common or helpful to represent what is essentially an indexed image in unit-scale instead of using integers. Finally, if the final character array is the goal, then the entire bit with converting to unit-scale is an entirely unnecessary complication. It's also not clear what "the corresponding numeric character alphabet letters" actually means.

Image Analyst
Image Analyst on 23 Sep 2023
Edited: Image Analyst on 24 Sep 2023
Hints: imread, rgb2gray, imshow, imresize, fprintf, size. With a double for loop over rows and columns and those 6 functions, you can read in, convert to gray scale, display, resize, and print out the numerical values of the 64x64 array to the command window.
This looks like a homework problem. If you have any questions ask your instructor or read the link below to get started:
Obviously we can't give you the full solution because you're not allowed to turn in our code as your own. But we can give you hints and advice on your own code.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!