首页 \ 问答 \ Array的toString()实现(toString() implementation for Array)

Array的toString()实现(toString() implementation for Array)

在我陈述我的问题之前,我要感谢所有帮助我解决上一个问题的人。 Anywho,即使我把它放到toString方法,我目前也得到了内存偏移量。 我已经阅读了关于toString方法的大部分问题并且有一些理解,我只是想确定我是否正确实现了这一点。 如果您认为这是一个多余的问题,我理解。 我在这里先向您的帮助表示感谢。

船类

import java.util.Scanner;
public class Ship{

    int type;
    public String [][] shipPiece = new String[11][11];
    Scanner in = new Scanner(System.in);
    //Coordinate xy = new Coordinate();
    //private Coordinate[] bawdPiece = {new section()};
public Ship(){

}
    public String[][] placeShip()
    {
       System.out.println();
       for(int x = 1; x<10; x++)
       {
           for(int y = 1; y<10; y++)
           {
               shipPiece[x][y] = "0";
               System.out.print("|" + shipPiece);
           }
       }
       return shipPiece;
    }
    public String toString()
    {
        StringBuilder temp = new StringBuilder();

        temp.append(shipPiece);
        return temp.toString();
    }

Before I state my question, I would like to thank everyone who helped me on my previous question. Anywho, I am currently getting the memory offsets as result even when I place it to the to a toString method. I've read most of the questions regarding the toString method and have somewhat of a understanding, I just wanted to make sure if I'm implementing this correctly. If you feel that this is a redundant question, I understand. Thanks for the help in advance.

Ship class

import java.util.Scanner;
public class Ship{

    int type;
    public String [][] shipPiece = new String[11][11];
    Scanner in = new Scanner(System.in);
    //Coordinate xy = new Coordinate();
    //private Coordinate[] bawdPiece = {new section()};
public Ship(){

}
    public String[][] placeShip()
    {
       System.out.println();
       for(int x = 1; x<10; x++)
       {
           for(int y = 1; y<10; y++)
           {
               shipPiece[x][y] = "0";
               System.out.print("|" + shipPiece);
           }
       }
       return shipPiece;
    }
    public String toString()
    {
        StringBuilder temp = new StringBuilder();

        temp.append(shipPiece);
        return temp.toString();
    }

原文:https://stackoverflow.com/questions/20410298
更新时间:2023-02-04 12:02

最满意答案

如果像素的空间位置不相关,您可以这样做:

datatoprocess=I(I<threshold);

阈值是将白色与黑色分开的值。 [ graythresh][1]是一个很棒的功能。 datatoprocess将是一个带有像素值的1xN数组。

相反,如果像素的空间位置相关,则需要修改函数以不对特定像素起作用。 最好的方法是将NaN值设置为您不想考虑的像素。

Itoprocess=I;
Itoprocess(I>threshold)=NaN;

如果没有关于你在图像中做什么的更多信息,这是任何人都可以达到的最佳状态。


If the spatial location of the pixels is not relevant, you could just do:

datatoprocess=I(I<threshold);

Being threshold a value that separates the white from black. [graythresh][1] is a fantastic function for that. datatoprocess will be a 1xN array with the pixel values.

If, instead, the spatial location of the pixels is relevant, then you need to modify your functions to not work on specific pixels. The best approach for this is generally setting NaN values in pixels you dont want to take into account.

Itoprocess=I;
Itoprocess(I>threshold)=NaN;

Without more information on what exactly are you doing with the image, this is the best anyone can get to.

相关问答

更多
  • 你可以做的一件事是本地均衡亮度和可能的饱和度。 如果您不使用YCrCb或HSV等高级空间,我建议您尝试使用它们。 你能否假设物体运动速度不太快? 如果您在检测程序中输入前一个位置,则可以减小正在查看的窗口的大小。 运动的速度和方向也一样。 我已经成功地使用了一个区域的直方图组合和形状描述符以便可靠地检测它,您可以使用它或将其添加到SURF / SIFT分类器。 One thing you can do is locally equalize brightness and possibly saturatio ...
  • 我猜你的问题是因为你的jpg掩码不是真正的二进制图像。 使用jpg存储二进制图像不是一个好主意,因为由于jpegs的压缩性质,你的掩码会略微偏离二进制图像,特别是在边缘。 要从jpeg掩码中获取真实的二进制图像,您可以尝试这样做: Ibw = im2bw(rgb2gray(imread('mask.jpg'))); 如果没有帮助,当你生成面具时,不要使用jpeg。 相反,在灰度级中使用未压缩(或无损压缩)tiff,或者仅将其存储为文件中的二进制matlab矩阵。 希望这可以帮助。 I guess that ...
  • 您可以使用bwboundaries查找白色连接组件的像素边界,这样每个连接的组件都有一组相应的边界。 %calculate boundries and generate boundry mask B = bwboundaries(im,'noholes'); boundriesImage = zeros(size(im)); boundriesPixels = cell2mat(B); boundriesImage(sub2ind(size(im),boundriesPixels(:,1),boundrie ...
  • 正如eykanal所说,你可以使用impoly函数在你的图像中创建你想要的任何ROI。 提取coordiantes的一般解决方案是创建所需的ROI,并使用find提取坐标和一些设置操作以删除不需要的点。 喜欢这个: imshow(image) h = impoly() ; %# draw ROI1 ROI1 = createMask(h); %# create binary mask of ROI1 h2 = impoly(); %# draw ...
  • 如果像素的空间位置不相关,您可以这样做: datatoprocess=I(Ithreshold)=NaN; 如果没有关于你在图像中做什么的更多信息,这是任何人都可以达到的 ...
  • 使用error_ellipse获取所需的置信区域。 你需要做的就是给它一个协方差矩阵(用cov(D)很容易得到,其中D是矩阵,其中每一行是一个平均移位点) 示例代码: D = randn(1000,2); mu = mean(D); Dm = bsxfun(@minus,D,mu); error_ellipse(cov(Dm),'conf',0.95,'mu',mu); hold on; plot(D(:,1),D(:,2),'r*'); Use error_ellipse to obtain the r ...
  • 根据评论中的说明,您正在尝试使用matlab创建支持Alpha透明度的视频格式。 一般来说,单独使用matlab似乎是不可能的(至少在matlab 2013中是我使用的版本)。 如果您想检查最新的matlab是否支持具有Alpha透明度的视频,请键入doc videowriter并查看可用的格式。 如果您在那里看到任何带有透明度选项的内容,请从那里开始。 但我看到的最多的是24位RGB视频(即三个频道,没有透明度)。 所以matlab没有能力生成具有alpha透明度的原生.avi视频。 但请注意,这是一种非 ...
  • 你正在做的是从面具外面的vessel中提取所有东西。 由于没有圆形矩阵这样的东西,Matlab的解决方案是输出掩码内所有值的向量 。 虽然这在技术上是正确的,但该向量可能很难处理。 另一种解决方案是将数据矩阵保持为正方形,并将掩码外的所有内容设置为NaN : % make a copy vessel_undermask = vessel; % NaN everything outside the mask (in R, G and B layers) vessel_undermask(re ...
  • 要真正“隐藏”感兴趣的区域:首先在all几何图形上设置颜色,然后通过指定水,公园,道路等的颜色来覆盖该设置。 代码示例: var myStyle = [ {featureType: "all", elementType: "geometry.fill", stylers: [{color: "#CCCCCC"}]}, {featureType: "water", elementType: "geometry", stylers: [{hue: "#99CCFF"}, {lightness: ...
  • 我没有找到任何关于更改循环的优化标志的内容,但是根据文档,您可以在函数上使用属性optimize ( 在此处和此处查看 )来覆盖该函数的优化设置,如下所示: void foo() __attribute__((optimize("O2", "inline-functions"))) 如果要为多个函数更改它,可以使用#pragma GCC optimize为所有后续函数设置它( 在此处查看 )。 因此,您应该能够使用不同的优化标志集编译包含裁剪的函数,省略自动向量化。 这样做的缺点是硬编码该函数的编译标志, ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)