当前位置:网站首页>Use matlab to generate pictures MIF file
Use matlab to generate pictures MIF file
2022-07-20 10:47:00 【Nanyou school slag】
List of articles
Preface
In the use of fpga When displaying pictures , Need to use ROM IP Nuclear to carry out the picture mif File storage , This article will use matlab Generate image's mif file
One 、 Generation steps
1. Process the image size
Use the drawing software provided by the computer , Change the pixel size of the picture , Change to the desired size
2. stay matlab New folder
Put picture files in the folder ,.bmp Format picture
3. Input code generation mif file
clear % Clean up the command line window
clc % Clean up the work area
% Use imread Function to read pictures , And transform it into a three-dimensional matrix
image_array = imread('picture.bmp');
% Use size Function to calculate the size of the three dimensions of the image matrix
% The first dimension is the height of the picture , The second dimension is the width of the picture , The third dimension is the picture dimension
[height,width,z]=size(image_array); % 100*100*3
red = image_array(:,:,1); % Extract the red component , The data type is uint8
green = image_array(:,:,2); % Extract the green component , The data type is uint8
blue = image_array(:,:,3); % Extract the blue component , The data type is uint8
% Use reshape The function reconstitutes each component into a one-dimensional matrix
% To avoid spillage , take uint8 Type of data is expanded to uint32 type
r = uint32(reshape(red' , 1 ,height*width));
g = uint32(reshape(green' , 1 ,height*width));
b = uint32(reshape(blue' , 1 ,height*width));
% Initialization to write .mif In the document RGB Color matrix
rgb=zeros(1,height*width);
% The imported picture is 24bit True color pictures , Each pixel occupies 24bit,RGB888
% take RGB888 Convert to RGB565
% The red component shifts to the right 3 Bit take out high 5 position , Move left 11 as ROM in RGB The number of data 15bit To the first 11bit
% The green component shifts to the right 2 Bit take out high 6 position , Move left 5 as ROM in RGB The number of data 10bit To the first 5bit
% The blue component shifts to the right 3 Bit take out high 5 position , Move left 0 as ROM in RGB The number of data 4bit To the first 0bit
for i = 1:height*width
rgb(i) = bitshift(bitshift(r(i),-3),11)+ bitshift(bitshift(g(i),-2),5)+ bitshift(bitshift(b(i),-3),0);
end
fid = fopen( 'image.mif', 'w+' );
% .mif File string printing
fprintf( fid, 'WIDTH=16;\n');
fprintf( fid, 'DEPTH=%d;\n\n',height*width);
fprintf( fid, 'ADDRESS_RADIX=UNS;\n');
fprintf( fid, 'DATA_RADIX=HEX;\n\n');
fprintf(fid,'%s\n\t','CONTENT');
fprintf(fid,'%s\n','BEGIN');
% Write picture data
for i = 1:height*width
fprintf(fid,'\t\t%d\t:%x\t;\n',i-1,rgb(i));
end
% Print end string
fprintf(fid,'\tEND;');
fclose( fid ); % Close file pointer
Pay attention to the third line of code , Write the file name of the image file , You need to fill in the file name of the saved image
4. File generation
Write the code and press enter to generate it in the folder mif The file
边栏推荐
- 今天来学习列表,超链接,图片标签和音视频的使用
- 高度塌陷及解决方案
- Model in pytorch train(),model. Eval () and torch no_ The difference between grad()
- How can platformization help improve R & D efficiency?
- 若依开源框架中数据权限的使用及配置
- FPGA仿真时使用任务及随机函数编写激励测试文件
- Implementation of UART serial asynchronous communication with FPGA - transmission of single data
- (一)DDL、DML、DQL、DCL与常见数据类型
- 模拟小米商城头部首页
- 小白程序员第七天
猜你喜欢
Detailed explanation of several connection queries
若依框架集成JimuReport积木报表
畅玩树莓派4B(一)树莓派系统安装和SSH连接
How can 3dslicer extension modules be added to external expansion packages?
(一)DDL、DML、DQL、DCL与常见数据类型
Basic knowledge of C language
FPGA基于串口RS232的数据收发及数据回环实验
Interview summary (total)
Summary 2 - deep learning network building learning
XPath filters other tags in the tag to get all the content
随机推荐
Pytoch:visdom introduction
Introduction to the structure of gocore-v2 framework scaffold generation project
小白程序员第七天
Examples of cat and dog classification -kaggle
Introduction to 3dslicer default extension module program
FPGA之阻塞赋值与非阻塞赋值的理解
Model in pytorch train(),model. Eval () and torch no_ The difference between grad()
浅谈Break和continue语句的区别
Use tasks and random functions to write excitation test files during FPGA simulation
Pytorch: Introduction à visdom
Verilog语法基础HDL Bits训练 01
FPGA之簡易頻率計的設計
boolean到底占几个字节?
小白程序员第六天
解决几个常见问题
Gocore-v2 framework API interface development concept
数据类型转换
Qt 日志文件系统
Tutorials of Feixun K1 brushing into feed and openwrt
小白程序员第八天