我正在尝试将图像切割成RGB,我在绘制这些图像时遇到问题.我使用此功能从某个文件夹中获取所有图像:
def get_images(path, image_type):
image_list = []
for filename in glob.glob(path + '/*'+ image_type):
im=misc.imread(filename, mode='RGB')
image_list.append(im)
return image_list
Run Code Online (Sandbox Code Playgroud)
这个函数创建了4d数组(30,1536,2048,3),我很确定第一个值代表图像数量,第二个和第三个是维度,第三个是RGB值.
在我获得所有图像后,我将它们存储为numpy数组
image_list = get_images('C:\HDR\images', '.jpg')
temp = np.array(image_list)
Run Code Online (Sandbox Code Playgroud)
之后我尝试使用简单的切片来从这些图像中获取特定的颜色:
red_images = temp[:,:,:,0]
green_images = temp[:,:,:,1]
blue_images = temp[:,:,:,2]
Run Code Online (Sandbox Code Playgroud)
当我打印出值时,一切似乎都很好.
print(temp[11,125,311,:])
print(red_images[11,125,311])
print(green_images[11,125,311])
print(blue_images[11,125,311])
Run Code Online (Sandbox Code Playgroud)
我得到以下内容:
[105 97 76]
105
97
76
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切似乎都很好,但是当我尝试显示图像时会出现问题.我曾经matplotlib.pyplot.imshow显示它,我得到的图像如下:
这是合理的,因为我选择红色:
plt.imshow(temp[29,:,:,0])
Run Code Online (Sandbox Code Playgroud)
但当我将其更改为不同的颜色通道时,如下所示:
plt.imshow(temp[29,:,:,2])
Run Code Online (Sandbox Code Playgroud)
我得到这样的图像:
我的问题很简单.这里发生了什么?
我在这个问题上摸索了一段时间,找不到问题所在。在 Windows 10 上运行 Docker Desktop。我有一个连接到 postgres 的 dotnetcore 3.1 api。这两个都在容器中运行。
除了与数据库的连接之外,一切似乎都正常。由于我查看了 docker-compose.yml 一百万次,我想不出任何其他想法。
这是我的连接字符串:
"Server=postgres;Port=5432;Database=IdentityManager;User Id=postgres;Password=12345678;"
Run Code Online (Sandbox Code Playgroud)
这是 docker-compose.yml 文件:
version: '3'
services:
identityserver:
depends_on:
- "postgres"
container_name: identityserver
build:
context: ./my_project/
dockerfile: Dockerfile
environment:
- ASPNETCORE_ENVIRONMENT='Development'
ports:
- "5000:80"
postgres:
image: "postgres"
container_name: "postgres"
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=12345678
- POSTGRES_DB=IdentityManager
expose:
- "5432"
Run Code Online (Sandbox Code Playgroud)
一切都建立起来,但与数据库的连接失败:
Unhandled exception. Npgsql.NpgsqlException (0x80004005): Exception while connecting identityserver
---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (99): Cannot assign requested address [::1]:5432
Run Code Online (Sandbox Code Playgroud)
最奇怪的是,当我在 docker-compose.yml 上使用相同的配置单独运行 postgres 时,并使用稍微不同的连接字符串在容器外部运行应用程序:
"Server=127.0.0.1;Port=5432;Database=IdentityManager;User …Run Code Online (Sandbox Code Playgroud) 我正在使用BigDecimal,但我仍然得到两个不同(数学上相同)表达式的不同结果:
第一个表达式:PI - (10 ^( - 14)/ PI)
第二表达式:(PI ^ 2 - 10 ^( - 14))/ PI
package set1;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class FloatingLaws {
final static BigDecimal PI = BigDecimal.valueOf(Math.PI);
public static void main(String[] args) {
System.out.println(firstExpression());
System.out.println(secondExpression());
}
private static BigDecimal secondExpression() {
return PI.subtract((BigDecimal.valueOf(Math.pow(10, -14)).divide(PI,50,RoundingMode.CEILING)));
}
private static BigDecimal firstExpression() {
return (PI.multiply(PI).subtract(BigDecimal.valueOf(Math.pow(10, -14)))).divide(PI, 50,RoundingMode.CEILING);
}
}
Run Code Online (Sandbox Code Playgroud)
执行此代码后,无论舍入有多大,最后一位数总是不同的.在我的情况下,我得到这两个结果:
3.14159265358978981690113816209304300915191180404867
3.14159265358978981690113816209304300915191180404866
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么会发生这种情况并且可以解决?
bigdecimal ×1
docker ×1
image ×1
java ×1
matplotlib ×1
numpy ×1
postgresql ×1
python ×1
scipy ×1