Reputation: 358
I want to create a jpg image with size 343 by 389 (Height by Width) with height as pixel values. For example for the whole topmost pixels, I need to give it as value 1, the next row of pixels should have a value 2. and finally, the last pixel with value 343. then export that image in jpg format. How to do this? either in python or in Matlab?
Upvotes: 0
Views: 157
Reputation: 4767
A solution in MATLAB using the meshgrid()
function may work. An important part is to caste the array Image
of type double
into an unsigned 8-bit integer array, uint8
before exporting it as a .jpg
using the imwrite()
function.
[~,Image] = meshgrid((1:389),(1:343));
imwrite(uint8(Image),"Depth.jpg");
Upvotes: 2
Reputation: 358
Did it
from PIL import Image
import numpy as np
a = np.empty(shape=(343, 389), dtype=int)
for i in range(343):
for j in range(389):
a[i,j]=i
im = Image.fromarray(a,'L')
im.save('depth.jpg')
Upvotes: 1