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
最满意答案
如果像素的空间位置不相关,您可以这样做:
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 ...
-
如何在matlab中提取感兴趣区域内的对象(how to extract the objects inside the region of interest in matlab)[2022-04-18]
正如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(I
threshold)=NaN; 如果没有关于你在图像中做什么的更多信息,这是任何人都可以达到的 ... -
2D分布兴趣区域(2D Distribution Region of Interest)[2022-03-23]
使用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为所有后续函数设置它( 在此处查看 )。 因此,您应该能够使用不同的优化标志集编译包含裁剪的函数,省略自动向量化。 这样做的缺点是硬编码该函数的编译标志, ...