在rawimage里展示出所选取的图片

先 public RawImage test;

在Unity内创建rawimage(所选取的图片会赋到其材质上)

 void LoadTexture()
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        //过滤器
        openFileDialog.Filter = "JPG|*.jpg|PNG图片|*.png";
        //当显示了Dialogue窗口之后  点击确认后执行if函数
        if(openFileDialog.ShowDialog() == DialogResult.OK)
        {
            string texPath = openFileDialog.FileName;
            Debug.Log(texPath);
            Texture2D tex2d = new Texture2D(1, 1);
            //将图片转为二进制存储
            byte[] texByte=File.ReadAllBytes(texPath);
            //从二进制形式加载出图片
            tex2d.LoadImage(texByte);
            //将加载出的图片赋给test的材质
            test.texture = tex2d;
        }
    }

 

### 使用MATLAB读取RAW文件并绘制图形 在MATLAB中,可以利用特定的函数来读取原始二进制(RAW)文件,并将其转换为可操作的数据结构以便进一步分析和可视化。下面展示了一个具体的实现方法以及对应的代码片段。 #### 函数定义 为了方便调用,在脚本或程序中先定义一个名为`readraw`的功能函数,该函数接收文件名作为输入参数,返回解码后的图像矩阵[^2]: ```matlab function image = readraw(filename) type = 'uint8'; fid = fopen(filename,'r'); if fid == -1 error('Cannot open file.'); end data = fread(fid, inf, type); fclose(fid); len = numel(data); % 假设两种可能分辨率之一适用当前数据长度 resolutions = struct('width',[640 1280],'height',[400 800]); resolutionIndex = find([resolutions.width .* resolutions.height] == len, 1); if isempty(resolutionIndex) warning('Data size does not match any predefined resolution!'); M = round(sqrt(len)); N = M; else M = resolutions.width(resolutionIndex); N = resolutions.height(resolutionIndex); end k = len / (M * N); image = permute(reshape(data,M,N,k), [2 1 3]); % 调整维度顺序以适应标准行列布局 end ``` 此部分实现了对不同尺寸图片的支持,当遇到未知大小时会尝试自动推断合理的宽高比例。 #### 数据加载与预览 接着编写一段简单的测试代码用来验证上述自定义函数的工作情况,并通过内置绘图命令快速查看结果: ```matlab % 设置路径到包含目标.raw文件的位置 filename = fullfile(pwd(), 'example.raw'); try img = readraw(filename); catch ME disp(['Error occurred while reading ', filename]) rethrow(ME) end figure(); subplot(1,2,1); imshow(img(:,:,1)/max(max(img(:,:,1)))); title('First Frame'); if size(img,3)>1 subplot(1,2,2); imshow(img(:,:,round(size(img,3)/2))/max(max(img(:,:,round(size(img,3)/2))))); title(['Middle Frame of Sequence (' num2str(size(img,3)) '-frames total)']); else axis off; text(.5,.5,'Only one frame available.',... 'HorizontalAlignment','center',... 'FontSize',14,... 'FontWeight','bold') end ``` 这段代码不仅能够处理单帧静态图像的情况,还考虑到了多帧序列的情形,对于后者则选取中间时刻的画面进行对比显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值