问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

怎样将BMP格式的图片转换成jpgl.jpegl.gifl.png格式的啊?

发布网友 发布时间:2022-04-08 05:05

我来回答

7个回答

懂视网 时间:2022-04-08 09:27

Dr. Chris Rose写的一个完整的程序,在他的程序基础上做了些修改,成功的将图像格式转换成了PNG格式。他的程序链接见http://microserf.org.uk/academic/Software.html

  从上面给出的链接下载到的程序中,有用户手册告诉你怎么使用这个程序。这个程序是用Ruby语言写的,需要在Cygwin下运行,用户手册中有介绍如何安装Cygwin及其他需要的工具。程序工作流程是使用者手动输入图像名称,程序先从FTP上下载该图像,然后经过几步转换,最终转换为PNG格式。我在按照用户手册运行这个程序时没有成功,用VS2013打开get-ddsm-mammo文件查看源码,发现是从FTP上下载图像环节出了问题,做了修改后,最终运行成功。我修改后的程序如下:    

#!/usr/bin/ruby

# This program gets a specified mammogram from the DDSM website and
# converts it to a PNG image. See the help message for full details.

require 'net/ftp'


# Specify the name of the info-file.
def info_file_name
 'info-file.txt'
end

def image_names
 'image_name.txt'
end

# Get an FTP file as specified by a DDSM path (e.g.,
# /pub/DDSM/cases/cancers/cancer_06/case1141/A-1141-1.ics) and return the
# local path to the file, or return nil if the file could not be dowloaded.
def get_file_via_ftp(ddsm_path)
 ftp = Net::FTP.new('figment.csee.usf.edu')
 ftp.passive = true
 ftp.login 
 ftp.chdir(File.dirname(ddsm_path)) 
 puts File.basename(ddsm_path) 
 ftp.getbinaryfile(File.basename(ddsm_path))
 #ftp.getbinaryfile(ddsm_path)
 
 # Will be stored local to this program, under the same file name
 
 # Check to make sure that we managed to get the file.
 if !FileTest.exist?(File.basename(ddsm_path))
 puts "Could not get the file #{File.basename(ddsm_path)} from the DDSM FTP server; perhaps the server is busy."
 exit(-1)
 end 
 return File.basename(ddsm_path)
end


# Return the string input with the system's filesep at the end; if there
# is one there already then return input.
def ensure_filesep_terminated(input)
 if input[input.length-1].chr != File::SEPARATOR
 input += File::SEPARATOR
 end

 return input
end

# Check program input; input is the program input (i.e ARGV).
def check_inputs(input)
 if input.length != 1
 puts get_help
 exit(-1)
 end
 
 # See if the user wanted the help docs.
 if input[0] == '--help'
 puts get_help
 exit(-1)
 end
 
 # Check to make sure that the info file exists.
 if !FileTest.exist?(info_file_name)
 puts "The file #{info_file_name} does not exist; use catalogue-ddsm-ftp-server.rb"
 exit(-1)
 end

end

# Given the name of a DDSM image, return the path to the
# .ics file associated with the image name. If we can't find the 
# path, then we return nil.
def get_ics_path_for_image(image_name)

 # Does image_name look right?
 if image_name[/._d{4,4}_...+/].nil?
 raise 'image_name seems to be wrong. It is: ' + image_name
 end

 # Edit the image name, as .ics files have the format 'A-0384-1.ics';
 # there is no '.RIGHT_CC' (for example).
 image_name = image_name[0..(image_name.rindex('.')-1)] # Strip everything after and including the last '.'.
 image_name[1] = '-'
 image_name[6] = '-' # Change the '_'s to '-'s (better regexp-based approach?).
 image_name+='.ics' # Add the file suffix.

 # Get the path to the .ics file for the specified image.
 File.open(info_file_name) do |file|
 file.each_line do |line|
 # Does this line specify the .ics file for the specified image name?
 if !line[/.+#{image_name}/].nil?
 # If so, we can stop looking		
 return line		
 end
 end
 end
 
 # If we get here, then we did not find a match, so we will return nil.
 return nil
end

# Given a line from a .ics file, return a string that specifies the
# number of rows and cols in the image described by the line. The
# string would be '123 456' if the image has 123 rows and 456 cols.
def get_image_dims(line)
 rows = line[/.+LINESsd+/][/d+/]
 cols = line[/.+PIXELS_PER_LINEsd+/][/PIXELS_PER_LINEsd+/][/d+/]

 return rows + ' ' + cols
end

# Given an image name and a string representing the location of a
# local .ics file, get the image dimensions and digitizer name for
# image_name. Return a hash which :image_dims maps to a string of the
# image dims (which would be '123 456' if the image has 123 rows and
# 456 cols) and :digitizer maps to the digitizer name. If we can't
# determine the dimensions and/or digitizer name, the corresponding
# entry in the hash will be nil.
def get_image_dims_and_digitizer(image_name, ics_file)
 # Get the name of the image view (e.g. 'RIGHT_CC')
 image_view = image_name[image_name.rindex('.')+1..image_name.length-1]

 image_dims = nil
 digitizer = nil

 # Read the image dimensions and digitizer name from the file.
 File.open(ics_file, 'r') do |file|
 file.each_line do |line|
 if !line[/#{image_view}.+/].nil?
 # Read the image dimensions
 image_dims = get_image_dims(line)
 end
 if !line[/DIGITIZER.+/].nil?
 # Read the digitizer type from the file.
 digitizer = line.split[1].downcase # Get the second word in the DIGITIZER line.

 # There are two types of Howtek scanner and they are
 # distinguished by the first letter in image_name.
 if digitizer == 'howtek'
  if image_name[0..0].upcase == 'A'
  digitizer += '-mgh'
  elsif image_name[0..0].upcase == 'D'
  digitizer += '-ismd'
  else
  raise 'Error trying to determine Howtek digitizer variant.'
  end
 end
 end
 end
 end

 # Return an associative array specifying the image dimensions and
 # digitizer used.
 return {:image_dims => image_dims, :digitizer =>digitizer}
end

# Given the name of a DDSM image, return a string that describes
# the image dimensions and the name of the digitizer that was used to
# capture it. If 
def do_get_image_info(image_name)
 # Get the path to the ics file for image_name.
 ftp_path = get_ics_path_for_image(image_name)
 ftp_path.chomp!
 
 # Get the ics file; providing us with a string representing
 # the local location of the file.
 ics_file = get_file_via_ftp(ftp_path)

 # Get the image dimensions and digitizer for image_name.
 image_dims_and_digitizer = get_image_dims_and_digitizer(image_name, ics_file)

 # Remove the .ics file as we don't need it any more.
 File.delete(ics_file)

 return image_dims_and_digitizer
end



# Given a mammogram name and the path to the image info file, get the
# image dimensions and digitizer name string.
def get_image_info(image_name)
 # Get the image dimensions and digitizer type for the specified
 # image as a string.
 image_info = do_get_image_info(image_name)
 
 # Now output the result to standard output.
 all_ok = !image_info[:image_dims].nil? && !image_info[:digitizer].nil? # Is everything OK?
 if all_ok
 ret_val = image_info[:image_dims] + ' ' + image_info[:digitizer]
 end

 return ret_val
end

# Return a non-existant random filename.
def get_temp_filename
 rand_name = "#{rand(10000000)}" # A longish string
 if FileTest.exist?(rand_name)
 rand_name = get_temp_filename
 end

 return rand_name
end

# Retrieve the LJPEG file for the mammogram with the specified
# image_name, given the path to the info file. Return the path to the
# local file if successful. If we can't get the file, then return nil.
def get_ljpeg(image_name)
 # Get the path to the image file on the mirror of the FTP server.
 path = nil
 
 File.open(info_file_name) do |file|
 file.each_line do |line|
 if !line[/.+#{image_name}.LJPEG/].nil?
 # We've found it, so get the file.
 line.chomp!
 local_path = get_file_via_ftp(line)		
 return local_path
 end
 end
 end

 # If we get here we didn't find where the file is on the server.
 return nil
end

# Given the path to the dir containing the jpeg program, the path to a
# LJPEG file, convert it to a PNM file. Return the path to the PNM
# file.
def ljpeg_to_pnm(ljpeg_file, dims_and_digitizer)
 # First convert it to raw format.
 command = "./jpeg.exe -d -s #{ljpeg_file}"
 `#{command}` # Run it.
 raw_file = ljpeg_file + '.1' # The jpeg program adds a .1 suffix.
 
 # See if the .1 file was created.
 if !FileTest.exist?(raw_file)
 raise 'Could not convert from LJPEG to raw.'
 end

 # Now convert the raw file to PNM and delete the raw file.
 command = "./ddsmraw2pnm.exe #{raw_file} #{dims_and_digitizer}"
 pnm_file = `#{command}`
 File.delete(raw_file)
 if $? != 0
 raise 'Could not convert from raw to PNM.'
 end

 # Return the path to the PNM file.
 return pnm_file.split[0]
end

# Convert a PNM file to a PNG file. pnm_file is the path to the pnm file
# and target_png_file is the name of the PNG file that we want created.
def pnm_to_png(pnm_file, target_png_file)
 command = "convert -depth 16 #{pnm_file} #{target_png_file}"
 `#{command}`

 if !FileTest.exist?(target_png_file)
 raise 'Could not convert from PNM to PNG.'
 end

 return target_png_file
end

#write image_names to image_nama.txt
def write_image_names(name)
 namefile=File.open(image_names,'a') 
 namefile.puts name
 namefile.puts "
"
 namefile.close
end

# The entry point of the program.
def main 
 # Check to see if the input is sensible.
 #check_inputs(ARGV)
 
 #image_name = ARGV[0]

 File.open('read_names.txt','r') do |file|
 file.each_line do |line|
	 image_name = line
	 image_name.chomp!
	 
	 # Get the image dimensions and digitizer name string for the
	 # specified image.
	 image_info = get_image_info(image_name)
 
	 # Get the LJPEG file from the mirror of the FTP site, returning the
	 # path to the local file.
	 ljpeg_file = get_ljpeg(image_name)
 
	 # Convert the LJPEG file to PNM and delete the original LJPEG.
	 pnm_file = ljpeg_to_pnm(ljpeg_file, image_info)
	 File.delete(ljpeg_file)

	 # Now convert the PNM file to PNG and delete the PNG file.
	 target_png_file = image_name + '.png'
	 png_file = pnm_to_png(pnm_file, target_png_file)
	 File.delete(pnm_file)

	 # Test to see if we got something.
	 if !FileTest.exist?(png_file)
		raise 'Could not create PNG file.'
		exit(-1)
	 end

	 # Display the path to the file.
	 puts File.expand_path(png_file)

	 #write image name
	 write_image_names(image_name)

	 #exit(0)
	end 
 end
 exit(0)
end

# The help message
def get_help
 <<END_OF_HELP

 This program gets a specified mammogram from a local mirror of the
 DDSM FTP Server, converts it to a PNG image and saves it to a target
 directory; if the target directory already contains a suitably-named
 file, the download and conversion are skipped.

Call this program using:

 ruby get-ddsm-mammo.rb <image-name>

 (Note: the '\' simply indicates that the above command should be on
 one line.)

 where:

 * <image-name> is the name of the DDSM image you want to get and
 convert, for example: 'A_1141_1.LEFT_MLO'.

 If successful, the program will print the path to the PNG file of
 the requested mammogram to standard output and will return a status
 code of 0. If unsuccessful, the program should display a
 useful error message and return a non-zero status code.

END_OF_HELP
end

# Call the entry point.
main
  很麻烦的一点是,原程序运行需要手动依次输入图像名称,一次只能处理一张图像,一张图像处理完后才能处理下一张,很费时费力,所以在上面贴出的程序中我还做了一点修改,可以批量处理图像。方法是将要处理的图像的名称提前写在一个txt文件里,命名为read_names,运行程序只需输入 ./get-ddsm-mammo即可。程序运行界面如下:

  技术分享  

  每处理完一张图像,程序会将图像的名称写在一个名为image_name的txt文件里,所以在运行程序前要先创建一个名为image_name的txt文件。

  最后一点要说明的是,用户手册中提到在安装Cygwin时要同时安装Ruby,因为当时的Cygwin版本较低,Ruby已不在手册中所示位置,而是单独拿出来的,要安装如下图所示的两个:技术分享

技术分享









版权声明:本文为博主原创文章,未经博主允许不得转载。

DDSM数据库转换图像格式——LJPEG转为PNG格式

标签:

热心网友 时间:2022-04-08 06:35

用photoshop打开这个图片,然后选“另存为”,就可以选择你想要的格式了

热心网友 时间:2022-04-08 07:53

用系统自带的画图工具,文件=>另存为

热心网友 时间:2022-04-08 09:27

photoshop

天空下载地址;http://www.skycn.com/soft/2426.html
无毒,放心

热心网友 时间:2022-04-08 11:19

把你的图片在WINDOWS自带的画图程序中打开,然后另存为,另存为的时候选择一下它的格式,就OK了

热心网友 时间:2022-04-08 13:27

用ACDsee转换

热心网友 时间:2022-04-08 15:51

谢谢你的问题,我也正想知道答案.虽然还没试过,但应该*不离十吧.
怎么将bmp格式的图片转为jpg,jpeg,gif格式?

会弹出来一个对话框,对话框里有一个格式,你在格式的右边下拉找到JPGE(*.JPGE;*.JPGE;*.jpe),保存即可。麻烦采纳,谢谢!

如何把doc文件转换成PDF格式?

"1.当然可以,首先要确定自己有一个pdf文档,而且确定目的是需要将pdf文档转换为word格式,然后我们将现有文档通过迅捷pdf转换器软件打开。2.通过选择PDF转换页面功能其中的PDF文件转WORD项目拖入文件。3.接着在迅捷pdf转换器下方按自己的需要是否更改文件名,然而在保存类型中选择*.doc选项。4.全部设置完成点击开始转换,确定自己设置好路径、更改文件名和保存类型即可。5.转换完成之后的word文档同样可以通过迅捷pdf转换器重新转换成一开始的pdf文档。"1.当然可以,首先要确定自己有一个pdf文档,而且确定目的是需要将pdf文档转换为word格式,然后我们将现有文档通过迅捷pdf转换器软件打开。2.通过选择PDF转换页面功能其中的PDF文件转WORD项目拖入文件。3.接着在迅捷pdf转换器下方按自己的需要是...

bmp转换为jpg格式,文件大小基本不变

怎么把BMP的图片内存大小不变转换成JPG的1、打开画板程序选择另存为即可也可以使用Photoshop软件打开后另存为jpg格式的图片:其它的一些支持bmp格式的软件也可以另存为jpg格式的。再不济可以直接用系统图片浏览功能打开bmp格式的图片,然后截图,就可以变成jpg了。2、第一步,点击软件工具左边最上方的【格式...

bmp格式转换jpg-如何用PhotoShop批量把.BMP文件转换成.JPG文件

1,打开软件,我们点击“格式转换”功能。2,点击“添加文件”按钮,将bmp格式图片添加到软件中,软件支持批量转换,所以我们可以一次性的添加多个图片到软件中。3,如下图所示位置,设置将图片格式转换成jpeg(jpeg和jpg是同一个格式),然后点击右上方位置的“开始转换”按钮,启动转换。4,当软件完成格式转换后,...

怎么把图片BMP格式的转换成JPG或者GIF或者PNG或者JPEG的大神们帮...

右键点你要转换的图片-打开方式--画图--然后点左上角的文件--另存为--在保存类型里选择JPEG即可

如何把大量BMP格式图片转换成JPG或JPEG格式

用ACDSEE打开其中一张图片,然后双击该图片,进入浏览窗口。这时候选中列表中的所有图片,右键选择转换

怎样把bmp图片转换成jpg?

1、首先在格式工厂软件的首页点击你要转换的最终格式【JPG】。2、进入到添加文件的操作页面以后,然后点击【添加文件】。3、接着选择你要改变格式的照片,然后点击下方的【打开】。4、进入到文件的确认页面以后,接着点击上方的【确定】。5、最后在任务的启动页面的上方点击【开始】就可以实现把bmp图片...

图片格式怎么转换jpg?实用方法全在这里

1. 打开浏览器,进入“快转图”网站。2. 选择“图片转格式”功能。3. 上传图片并选择jpg格式。4. 点击“开始转换”,转换完成后下载图片。方法三:使用Photoshop软件转换 Photoshop支持多种格式转换,包括png、gif、tiff、bmp等。具体步骤如下:1. 打开图片,选择“文件”-“另存为”。2. 选择JPEG...

怎么才能把图片转换成bmp格式图片转换成jpg.gif格式的图片?

1、最简单的方式:直接打开picrr在线编辑网站,然后再打开你的BMP图片,点另存为的时候选择你想要格式保存就行了,你可以保存到你本地,也可以保存在网络上 2、下载一个格式工厂,这个我没用过,但是网络上说这个还比较好用,缺点就是还需要去百度搜索再下载。3、如果你电脑装了PS,那就直接打开PS再...

如何将BMP格式的图象转换成JPEG或GIF的格式?

问题描述:我使用电脑摄像头拍了好多照片,但格式是BMP的,我想把这些照片上传到我的网页上,可是格式不支持.所以想请教各位该如何去做?解析:很简单!!!你先打开图片!!!随后另存为jpeg或gif图片 如: 你以前是 1.bmp 你 就可以改为 1.jpeg格式 只要 后面是 .jpeg或者 .gif 就行了!

图片格式是.bmp格式,我想改为.jpg或 .gif或 .png,有什么办法

打开画图程序》》文件》》另存为》》在保存类型的下拉框中选择你想要的图片格式

jpeg怎么转换成jpg格式 如何将png格式转化为jpg格式 怎么把图片转换成pdf格式 jpg格式怎么转换成pdf img格式图片 转换jpg pdf转换jpg图片格式 jpg图片怎么转换成pdf psd格式怎么转换成jpg 照片格式怎么转换jpg
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
求好看的重生文,不要重生回到以前的,女主性格不能软弱无能,不能太... 求双洁的娱乐圈小说(男女主或攻受一定要都身心干净,并且要重生的 )可 ... ...文笔一定要好 重生娱乐圈什么的都无所谓 一定要是婚后的! 浙江高考成绩理科专科排名查询怎么查啊,最好给网站谢谢 各高校是怎么依照高考成绩录取 四不像是什么样的动物 孔家后人为什么要把“四不像”刻在孔府内的照壁上? 中国龙和外国龙的区别西方龙的区别 山东省烟台市高新技术产业开发区的车牌号是什么? 电脑重装系统按个键-(电脑重装系统按个键没反应) 过期的米线可以吃吗 过期几天的米线还能吃吗 有什么相见恨晚的每日健身小知识? 真人版芭比的真人见面 诗歌朗诵如何站位 如何把抖音字体调大 今年双十一各大购物平台的销量如何? 干米线过期了还能吃吗 存储空间里的其他怎么删除 今年的双十一你都买了啥? 今年什么时候是双十一? 梦见自己戴了条白金项链被人抢了又被自己抢回来了是什么意思? 大佬们,新电脑怎么装win10系统 细数“神仙姐姐”过往的古装扮相,小龙女赵灵儿,哪一个才是你的最爱? 梦见黄金白金红金项链都一起戴? 主角的老婆小龙女赵灵儿王语嫣……书名是什么 已婚女人梦见戴金项链很勒然后摘下来? 对照刘亦菲接连饰演小龙女赵灵儿,受张艺谋李少红无顾偏爱的她有何实力? 被闺蜜搭档夺走男友的羽毛球奥运冠军赵芸蕾现在感情生活如何? 我用手机QQ上线时对方用电脑上QQ他能查到我的地理位置吗??? 剪映上传为什么不是原图苹果手机 痔疮一般用什么药最好 过期米线可以喂鸡吗? 挽回女朋友见面送什么东西 虽说“大个儿门前站,不穿衣服都好看”,但是个高的女生怎样搭配衣服才能凸显气质呢? 袋装过桥米线过期还能吃吗 你们认为回头率最高的星座是谁? 高个子秋冬季如何搭配衣服 米线过期了还能吃吗 自创的现代古诗和古诗(短点的 急!) 袋装的过桥米线过期五个月还能吃吗 个子高的女生怎么搭配衣服 俄罗斯的圣诞节是几号? 黑白棋软件下载在哪能下,谢谢 米线真的不能吃吗 个子很高的男生如何来搭配衣服? 那里有比较好些的php教程下载? 黑白棋残局app在哪下载? 过桥米线过期了,里面料包还能用吗 bilibili弹幕的填充是什么?