How i can convert any type of image to ASCII values and store these values into one-dimensional array?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Radhwan Jawad
am 4 Dez. 2022
Kommentiert: Radhwan Jawad
am 5 Dez. 2022
Hello matlab community.
I want to convert any type of image ( color or gray scale image ) to ASCII values and store these values into one-dimensional array for ex., if read my image as: A = imread(filename);, i want the final results(ASCII values ) appears in one-dimensional array(ex: B=[150,146,....), so that later on, I can reconstruct the original image.
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 4 Dez. 2022
I don't understand why you want to do that. If you want the original image later, just make a copy of A before you alter it.
You can make a 1-D list B from A like this
B = A(:)
Not sure what you're going to do with that though if A is a color image. If you have a gray scale image it's just column 1, then column 2, then column 3, etc. until the last column of the image, but I'm not sure why you'd want this.
If you want to make an ASCII text file with the location and color value in a CSV file, see the attached demo.
6 Kommentare
Image Analyst
am 5 Dez. 2022
SIZE_OF_IMAGE = size(YourImage);
where you of course replace "YourImage" with the actual name you used for your image variable.
Or you could do this:
[rows, columns, numberOfColorChannels] = size(YourImage)
output = reshape( permute(YourImage, [3 1 2]), 1, []);
reconstructed = permute(reshape(output, numberOfColorChannels, rows, columns), [2 3 1]);
Weitere Antworten (1)
Walter Roberson
am 4 Dez. 2022
Bearbeitet: Walter Roberson
am 4 Dez. 2022
N = ndims(YourImage);
indices = cell(1,N);
idx = find(YourImage);
[indices{:}] = ind2sub(size(YourImage), idx);
values = YourImage(idx);
T = [values(:), indices{:}];
Now T is an array with multiple columns. The first column is a pixel value; the remaining columns are indices -- row, column at the very least; if the 4th column is present it is channel number.
This code does not record the location of any pixels that are zero.
2 Kommentare
Walter Roberson
am 4 Dez. 2022
reconstructed = accumarray(T(:,2:end), T(:,1));
This will not work exactly as desired if it happens that there are rows or columns along the right edge or top edge that are all black: for that case you would need to know what the original size of the image is.
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!