小编Cie*_*eja的帖子

计算白色和黑色像素

我正在编写一个计算黑白像素的函数.
是否有Matlab计算白色和黑色像素的功能?
我知道我可以使用size方法和2 for循环和计数.
像这样的东西:

[row, column]= size(im);
cb = 0;
cw = 0;
for i=1:row
    for j=1:column
        if(im(i,j) == 0 )
            cb = cb + 1;
        end
        if(im(i,j) == 255)
            cw = cw + 1;
        end
    end
end
Run Code Online (Sandbox Code Playgroud)

但我正在寻找一些更简单的方法.你知道吗?

matlab image-processing

1
推荐指数
1
解决办法
1916
查看次数

构造函数 - 内存分配失败

我有一个构造函数,用r行和c列创建和清空A.

A::A(int r, int c)
    : row(r), column(c), e(new int[r*c])
{
    for (int i = 0; i < r*c; i++)
    {
        e[i] = 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

我想知道内存分配是否会失败,它仍然会使用非零值初始化行和列.我该怎样预防呢?

c++ arrays constructor multidimensional-array

1
推荐指数
1
解决办法
131
查看次数

String - 方法ToString

是否可以使用自定义格式的ToString()方法显示字符串?

例如,我有字符串:"123456789",我想显示为"123 456 789".

我试过这样的:

string myString = "123456789"
mystring = myString.ToString("{0:### ### ###}")
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

.net c# string asp.net-mvc tostring

0
推荐指数
1
解决办法
249
查看次数

Asp.Net Core [FromQuery] 绑定

我在使用 [FromQuery] 属性进行模型绑定时遇到问题。

我有以下课程:

public class PaginationSettings
{
    public const int DefaultRecordsPerPage = 5;

    public PaginationSettings(int pageIndex, int recordsPerPage)
    {
        RecordsPerPage = recordsPerPage == 0 ? DefaultRecordsPerPage : recordsPerPage;
        PageIndex = pageIndex == 0 ? 1 : pageIndex;
    }

    public int RecordsPerPage { get; set; }
    public int PageIndex { get; set; }
    public int RecordsStartIndex => RecordsPerPage * (PageIndex - 1);

    public static PaginationSettings Normalize(PaginationSettings source)
    {
        if (source == null)
        {
            return new PaginationSettings(0, 0);
        }

        return new …
Run Code Online (Sandbox Code Playgroud)

.net c# model-binding asp.net-core asp.net-core-webapi

0
推荐指数
1
解决办法
4935
查看次数