- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先我要警告你,我只是一个试图让事情发挥作用的物理学家,我对 C++ 的知识基本上是不存在的。
我目前正在使用 GATE 模拟 CT 扫描仪,我需要将输出转换为 bmp 文件。
Gate 制作了一系列 file_xxx.dat,其中 xxx 的范围从 000 到您所做的投影数,每个都包含一个 32 位 float 数组,一个对应于您的检测器具有的每个像素。
我需要获取它们中的每一个并添加一个灰度 bmp header ,以便我可以用另一个程序重建它们。在此过程中,我想保留 32 位精度,这样我就不会丢失像素中的任何信息,因此如果可能的话,它会是 32 位灰度。
我一直在使用 Gate 的另一个输出,一个根文件,试图让 bmp header 工作。我宁愿避免使用根文件,因为它会迫使我浏览大量不需要的信息,并且会减慢处理速度。
这段代码的一部分是我写的,我复制粘贴了其他部分,还有一些部分是我的同事完成的,大部分时间我几乎不知道自己在做什么。
#include <iostream>
#include <fstream>
#include <ostream>
#include <cerrno>
#include <cstdlib>
#include <set>
#include <cmath>
#include "TApplication.h"
#include "TFile.h"
#include "TTree.h"
using namespace std;
#define MAX_ANGLES 180
#define PIXELS_X 100
#define PIXELS_Y 100
#define MAX_PIXELS 10000
struct SDataA
{
float A[MAX_ANGLES][MAX_PIXELS];
void Reset()
{
for (int a=0; a<MAX_ANGLES; a++)
{
for (int p=0; p<MAX_PIXELS; p++)
{
A[a][p] = 0.0;
}
}
}
};
int main( int argc, char* argv[] )
{
if( argc < 2 )
{
cerr << "arguments missing" << endl;
cerr << "Usage : AnalyzeCT myFile.root " << endl;
exit( EXIT_FAILURE );
}
// Store the root file name in 'fileName' variable
char* const FILENAME = argv[ 1 ];
// parameters for the histograms
float a;
SDataA *dataA=NULL;
dataA = new SDataA;
dataA->Reset();
int maxangles=MAX_ANGLES;
int pixelsx=PIXELS_X;
TApplication app( "Application", &argc, argv );
// Open (check) and read the root file
TFile* file = new TFile( FILENAME );
if( !file->IsOpen() )
{
cerr << "problem opening the root file : '" << FILENAME << "'" << endl;
cerr << strerror( errno ) << endl;
exit( EXIT_FAILURE );
}
// Take the single tree, where is the position, the energy and the runID
TTree* singlesTree = (TTree*)file->Get( "Singles" );
Int_t runID, pixelID;
singlesTree->SetBranchAddress( "runID", &runID );
singlesTree->SetBranchAddress( "pixelID", &pixelID );
// Number of entries in the single tree
Int_t entriesSingleTree = (Int_t)singlesTree->GetEntries();
cout << "Number of detected photons : " << entriesSingleTree << endl;
for( Int_t i = 0; i != entriesSingleTree; ++i )
{
singlesTree->GetEntry( i );
if ((runID < MAX_ANGLES) && (pixelID < MAX_PIXELS))
{
dataA->A[runID][pixelID] += 1;
a=dataA->A[runID][pixelID];
// cout << "A[" << runID <<"]["<< pixelID<<"] ="<< a << endl;
}
}
std::ofstream ofile("Slice.bin", std::ios::binary);
int currangle=0;
short BM=19778;
short bfReserved=0,biPlanes=1,biBitCount=32;
int bfSize=54+40000, bfOffBits=54, biSize=40, biWidth=PIXELS_X, biHeight=PIXELS_Y,Zero=0,biClrUsed=1;
ofile.write((char*) &BM, sizeof(short));
ofile.write((char*) &bfSize, sizeof(int));
ofile.write((char*) &bfReserved, sizeof(short));
ofile.write((char*) &bfReserved, sizeof(short));
ofile.write((char*) &bfOffBits, sizeof(int));
ofile.write((char*) &biSize, sizeof(int));
ofile.write((char*) &biWidth, sizeof(int));
ofile.write((char*) &biHeight, sizeof(int));
ofile.write((char*) &biPlanes, sizeof(short));
ofile.write((char*) &biBitCount, sizeof(short));
ofile.write((char*) &Zero, sizeof(int));
ofile.write((char*) &Zero, sizeof(int));
ofile.write((char*) &Zero, sizeof(int));
ofile.write((char*) &Zero, sizeof(int));
ofile.write((char*) &biClrUsed, sizeof(int));
ofile.write((char*) &Zero, sizeof(int));
for ( Int_t k =currangle ; k<currangle+1; k++){
for (Int_t j=0; j<MAX_PIXELS; j++){
a=dataA->A[k][j];
//cout<< dataA->A[k][j]<< endl;
ofile.write((char*) &a, sizeof(float)); //s1
}
}
ofile.close();
cout << "Done" << endl;
delete singlesTree;
delete gateTree;
app.Run();
return 0;
}
可能有些 block 看起来不完整,但那是因为我一直在删除原始代码中被注释掉的一些部分,现在它真的是弗兰肯斯坦的怪物。
问题是我实际上得到了一个 40054 字节长的文件(标题中有 54 个字节,我的 10000 个 float 中有 40000 个字节)然后我将其重命名为 .bmp 以查看它是否可以读取但是有没办法,我猜头上可能有一些不一致的定义,但我一点头绪都没有。
我也尝试过使用 opencv 来读取我的 dat 文件,但是我的机器出了问题,我所能解决的就是错误
编辑:1)这是一个 dat 文件 https://ufile.io/86210我用酰胺打开它们,它们包含模拟生成的投影之一。我想一个 float 对于它现在包含的数字来说可能太多了,但我可能不得不进入具有更高计数的模拟。
编辑:2)是的,biSize 没有设置,现在 biSize=40 有效图像全是红色和黑色,但看起来应该是这样。该链接就像之前以/0a111 结尾的链接(我需要更多声誉才能发布)我很抱歉这是一件愚蠢的事情,我已经苦苦挣扎了好几天,但我失去了注意力
如果有任何更好的链接文件的方法,请告诉我
最好的问候,
阿桑奇
最佳答案
如果您使用安装在大多数 Linux 发行版上并适用于 macOS 和 Windows 的 ImageMagick,则无需编写任何软件即可将此数据转换为常规图像格式。
如果我们假设您的 10,000 个 float 对应于一个 100x100 像素的图像,每个像素都是一个 float ,并且在一个名为 image.bin
的文件中,您可以在命令中键入它获取规范化浮点 TIF 文件的行:
convert -size 100x100 -depth 32 -define quantum:format=floating-point gray:image.bin -normalize result.tif
如果您不希望规范化的数据填满整个范围,请省略 -normalize
。
如果您想要一个 PNG
文件而不是一个 TIF
,只需将 result.tif
更改为 result.png
如果您的数据是小端/大端,请添加-endian lsb
或-endian msb
。
我似乎无法下载你的大文件,但如果你有一个 54 字节的文件头要删除,你可以将命令更改为如下内容:
convert -size 100x100+54 -depth 32 -define quantum:format=floating-point gray:image.bin -normalize result.tif
或者使用诸如 dd
之类的外部实用程序来删除 54 字节的 header :
dd if=image.bin bs=54 skip=1 | convert -size 100x100 -depth 32 -define quantum:format=floating-point gray:- -normalize result.tif
关于c++ - 添加 BMP 灰度 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40303430/
我在让“@header”或任何其他@规则在ANTLR中工作时遇到麻烦。具有非常基本的语法,如下所示: grammar test; options { language = CSharp2;
我对来源和寄宿有疑问 我有一个ajax页面“Page A”,它将称为ajax提要“Page B” 我看到来自ajax调用的“页面B”的请求 header 具有源“http://mydomain.com
我在 pandas 中使用了数据透视表并获得了所需的数据框格式,但现在我有两行标题。数据透视表后的结果数据框如下: scenario Actual Plan
我在 pandas 中使用了数据透视表并获得了所需的数据框格式,但现在我有两行标题。数据透视表后的结果数据框如下: scenario Actual Plan
我想在主机将它们发送到网络之前修改数据包头(IP 头、TCP 头)。 例如,如果我使用 firefox 进行浏览,那么我想拦截所有来自 firefox 的数据包并修改 IP/TCP header ,然
我的 header 内容被包装到#header 中,但是当我设置边框显示结构时,它显示我的#header 的内容出现在#header 本身之后。可能是什么问题?这是我的代码: #header { bo
我是一名 Web 开发人员,使用过 PHP 和 .NET。有一年多的 Web 工作经验,我一直无法彻底了解浏览器缓存功能,希望这里的 Web Gurus 可以帮助我。我心中的问题是: 浏览器实际上是如
伙计们,我有一个问题,我不知道如何在一个 header 中连接多个 header ,我们称它为“主 header ”并使用该 header 中的函数,例如 // A.h #include class
我有一个包含 SOAP 消息的 XMLHTTPRequest。 我想添加用于标识消息并将由 C# Web 服务使用的 guid。 GUID 的目标是识别特定用户,并应护送所有用户请求以在服务器上进行身
我一直在阅读粘性标题,这是我目前所发现的。第一个粘性 header 效果很好,但是当它遇到第一个 header 时,我如何向上滚动第一个 header 并使第二个 header 卡住? http://
我想将当前基于 TableView 的数据网格转换为新的 UICollectionView 类。 这就是我当前的网格的样子: 我的网格有两个标题: 年份(2006a、2007a 等)和 类型(“收入”
我目前正在使用 Apollo 服务器。我正在尝试在响应 header 中设置一个属性。并且此属性是从客户端 graphQL 请求 header 中检索的。 我在网上查了一下。并看到了诸如使用插件或扩展
我的 Controller 的方法需要设置一个标题,例如X-Authorization .创建新对象( store Action )后,我执行转发以显示新创建的对象( show Action ): $
我正在研究一些关于 VLAN 的事情,发现了 VLAN 标签 和 header 。 如果我们有标准 802.3 以太网帧 的 MTU(1518 字节), header 802.3 中包含什么? 另外,
我是放心和 Java 的新手,我正在尝试做一个非常基本的测试来检查 API 的响应是否为 200 ok。 谁能告诉我我需要在下面的脚本中更改什么才能传递多个 header Id、Key 和 ConId
在我的项目中,我需要知道 zlib header 是什么样的。我听说它相当简单,但我找不到 zlib header 的任何描述。 例如,它是否包含魔数(Magic Number)? 最佳答案 zlib
我正在使用 JMeter 测试 HTTP 服务器,该服务器接受并验证 APIKey 并在成功时返回一个有时限的 token 。如果我有 token ,我想发送一个 token ;如果没有,我想发送一个
以太网 header 是什么样的? 是吗: 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|
我们的应用程序支持 CORS 配置 header 。我在两个不同的主机上分别配置了 testApp。两种设置都相互独立工作。host1 上的应用程序配置有 CORS header Access-Con
tlhelp32.h 不包含 windows.h 本身是有原因的吗?我一直在与大量的编译器错误作斗争,因为我在包含 tlhelp32.h 之后包含了 windows.h。这是设计决定还是出于什么原因?
我是一名优秀的程序员,十分优秀!