使用C ++进行图像处理 [英] Image processing with C++

查看:452
本文介绍了使用C ++进行图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大学作业,我需要做基本的图像处理,如打开图像,重新抽样,缩放和一些基于像素连接的操作。



有任何库,使事情更容易,如jpg查看和启用像素级访问?将OpenCV是一个好的选择,如果是这样,我应该使用的库是什么?



(我不想直接调用库方法做这个任务需要

解决方案



我建议您使用ImageMagick将图片转换为PBM / PGM或PNM格式(如此处),那么你可以很容易地读取在C ++中的图像,并以相同的,非常容易的格式

  P1(或P2-P6)
宽度高度(ASCII文本)
像素像素像素像素...
像素像素像素像素...



这样你可以专注于图像处理和像素连接,而不用担心运行长度编码,调色板或JPEG DCT等。



要将JPEG转换为PNM,只需使用ImageMagick的 convert 工具

  convert image.jpg image.pnm 

或TIF到PPM

  convert image.tif image.ppm 

如果您希望NetPBM格式P1-P3具有ASCII像素数据而不是二进制,请使用选项 -compression none 与ImageMagick的 convert 命令,即

  convert image.jpg -compresssion none image.pnm 

,而如果你想要NetPBM格式P4-P6,使用二进制像素数据, c> -compression none 参数:

  convert image.jpg image.pnm 


I have a college assignment where I need to do basic image processing such as opening an image, re-sampling, scaling and some pixel connectivity based operations.

Is there any library to make things easier such as jpg viewing and enabling pixel level accessing? Will OpenCV be a good option if so what are the libraries that I should be using?

(I do not want to directly call library methods to do them as this assignment needs to be done some what manually)

Thank you in advance.

解决方案

I suggest you use ImageMagick to convert your images to PBM/PGM or PNM format (as described here) then you can easily read the images in in C++ and write them out in the same, very easy format which is just

P1 (or P2-P6)
width height (in ASCII text)
pixel pixel pixel pixel ...
pixel pixel pixel pixel ...

That way you can concentrate on the image processing and pixel connectivity rather than worrying about run-length encoding, palettes or JPEG DCTs etc.

To convert a JPEG to PNM just use ImageMagick's convert tool

convert image.jpg image.pnm

or a TIF to PPM

convert image.tif image.ppm

If you want NetPBM formats P1-P3 which have ASCII pixel data rather than binary, use the option -compression none with ImageMagick's convert command, i.e.

convert image.jpg -compresssion none image.pnm

whereas if you want NetPBM formats P4-P6, with binary pixel data, leave off the -compression none parameter:

convert image.jpg image.pnm

这篇关于使用C ++进行图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆