我有一组RGB值。我需要将它们放在单个像素中。我使用from PIL import Image
im = Image.open('suresh-pokharel.jpg')
pixels = im.load()
width, height = im.size
for i in range(width):
for j in range(height):
print(pixels[i,j]) # I want to put this pixels in a blank image and see the progress in image
进行了此操作,但是我需要一张一张地绘制像素并查看进度,而不是获取最终图像。
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { AmplifyService } from 'aws-amplify-angular';
@Injectable({
providedIn: 'root'
})
export class PrivateGuard implements CanActivate {
constructor (private _router: Router,
private _amplifyService: AmplifyService) {}
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
return this._amplifyService.authStateChange$.pipe(map(authState => {
console.log(authState);
if (authState.state === 'signedIn') {
return true;
}else{
this._router.navigate(['/login']); // Why Never redirect?
return false;
}
})
);
}
}
答案 0 :(得分:2)
您可以生成以下内容:
具有以下代码(对于numpy
提示,@x Smarkell):
import imageio
import numpy as np
from PIL import Image
img = Image.open('suresh-pokharel.jpg')
pixels = img.load()
width, height = img.size
img2 = Image.new('RGB', img.size, color='white')
pixels2 = img2.load()
i = 0
images = []
for y in range(height):
for x in range(width):
pixels2[x, y] = pixels[x, y]
if i % 500 == 0:
images.append(np.array(img2))
i += 1
imageio.mimsave('result.gif', images)
或者这个:
具有以下代码:
import random
import imageio
import numpy as np
from PIL import Image
img = Image.open('suresh-pokharel.jpg')
pixels = img.load()
width, height = img.size
img2 = Image.new('RGB', img.size, color='white')
pixels2 = img2.load()
coord = []
for x in range(width):
for y in range(height):
coord.append((x, y))
images = []
while coord:
x, y = random.choice(coord)
pixels2[x, y] = pixels[x, y]
coord.remove((x, y))
if len(coord) % 500 == 0:
images.append(np.array(img2))
imageio.mimsave('result.gif', images)