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

截图得到的图片怎么转换成.jpgl .jpegl .gifl .png格式啊?

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

我来回答

2个回答

懂视网 时间: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

截到图片后打开画图,然后另存为,在下面有个保存格式,里面就有选择的
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
消防员不是军人为什么要敬礼 安全数据库安全数据库定义 求一部2014上映欧美科幻机器人的 她丈夫好像是科学家还是发明机器人的后... 求一个四个字的游戏军团名,大方霸气点的!急急急! 玩终结者2,想开挂,不知道这个软件有用吗,要收费怕被骗了 胰腺炎会导致腹泻吗 慢性胰腺炎为什么会引起腹泻? 胰腺炎会拉肚子吗 胰腺炎腹泻的原因 慢性胰腺炎患者会出现腹泻吗 求一个简单的黑白棋java可执行代码, 运行的时候输入坐标然后进行运算吃子儿的那种 mrp格式游戏下载 和Vivo手机语音智能助手jovi下五子棋怎么切换黑白棋(就是怎么切换先后手。)? 送女友的生日礼物哪些好? 有什么百变小樱的游戏吗?最好是gba之类的。 PHP有什么好的教程,在那下载? 送女友生日礼物送什么好? 求MSN翻转棋下载 请问一个身高160cm体重63公斤的22岁女孩怎么搭配衣服 俄罗斯的传统圣诞节日期 怎么做这样的弹幕? WINDOWS翻转棋.黑桃王.双陆棋.跳棋下载 php学习教程,能直接下载的教程,求学习过的朋友推荐下 求!!!单机版中国象棋下载地址 b站弹幕礼仪题? 吃了过期米线佐料怎么办,米线有股酸味,吃了好多才发现 俄罗斯圣诞节 C语言 黑白棋设计的流程图 用网络RTK测1:2000地形图的步骤,尤其是控制测量的部分,该如何进行,图根点又如何进行!在线等 女朋友要过生日了,想给她买几件礼物,有什么合适的推荐吗? 汽车电瓶没电了,能充电吗? 汽车电瓶没电了可以用交流充电吗 我的汽车放了半年没动过,然后电瓶一点电都没有了,搭线启动之后怠速可以充电么?需要充多久充满? 汽车电瓶没电了可以用电动车电瓶充电吗 PIC_2683.jpg.lnk 怎么转换成.jpgl.jpegl.gifl.png 格式啊? 苹果手机摄宽屏怎么办? 彩票双色球什么时候开奖 银行存款增值收入是什么 中国银行怎么样存钱才有利息? 怎样把手机图片转换成.jpgl.jpegl.jifl.png 你好,我手机现在死机了,打也打不开,我该怎么办? OPPO手机直接死机也打不开该怎OPPO手机直接死机也打不开,这该怎么办? 手机死机打不开怎么办 如何将美国南佛里达大学DDSM数据库中的LJPEG格式的图片转换成常规可用的图片? 查看占用内存最多的进程 黑白棋攻略 最长寿老人下黑白棋登热搜,长寿有什么秘诀? 元旦的别称是什么? 元旦的别名是什么呢? 元旦还有哪些称谓?