首页 > 其他分享 >PPM Image Transformations

PPM Image Transformations

时间:2024-09-12 12:13:39浏览次数:1  
标签:files Transformations Image PPM file pbm ppmcvt image

PPM Image Transformations

Learning ObjectivesUpon completion of this assignment, you should be able:

  1. To develop, compile, run and test C programs in a Linux environment
  2. To navigate Linux command lines reliably

The mechanisms you will practice using include:Linux command lines: manual pages, Linux commandsC Programming: structs, pointers, memory allocation, getoptProgram SpecificationNAMEppmcvt – convert ppm files

SYNOPSIS

ppmcvt [bg:i:r:smt:n:o:] file

DESCRIPTION

ppmcvt manipulates input Portable Pixel Map (PPM) files and outputs a newimage based on its given options. Only one option that specifies a

transformation can be used at a time.In the synopsis, options followed by a ‘:’ expect a subsequent parameter.The options are:

-bconvert input file to a Portable Bitmap (PBM) file. (DEFAULT)

-g:convert input file to a Portable Gray Map (PGM) file using the specifiedmax grayscale pixel value [1-65535].

-i:isolate the specified RGB channel. Valid channels are “red”, “green”, or“blue”.

-r:remove the specified RGB channel. Valid channels are “red”, “green”,or “blue”.

-sapply a sepia transformation

-mvertically mirror the first half of the image to the second half

-t:reduce the input image to a thumbnail based on the given scalingfactor [1-8].

-n:tile thumbnails of the input image based on the given scaling factor [1-8].

-o:write output image to the specified file. Existent output files will beoverwritten.

EXIT STATUSppmcvt exits 0 on success and 1 on failure.

EXAMPLES

ppmcvt -o out.pbm in.ppmread in.ppm PPM file and write converted PBM file to out.pbmppmcvt -g 16 -o out.pgm in.ppmconvert the PPM image in.ppm to a PGM image in out.pgmppmcvt -s -o out.ppm in.ppmapply a sepia transformation to the PPM image in in.ppm and outputthe new image to out.ppm

ppmcvt -n 4 -o out.ppm in.ppmtile 4 1:4-scaled (quarter-sized) thumbnails of the image in in.ppm intoa new PPPM image in out.ppm.

ERRORS

ppmcvt should print to the standard error output stream exactly thespecified line and then exit under the following circumstances:

"Usage: ppmcvt [-bgirsmtno] [FILE]\n": malformed command line"Error: Invalid channel specification: (%s); should be 'red', 'green' or 'blue'\

n”

"Error: Invalid max grayscale pixel value: %s; must be less than 65,536\n"

"Error: Invalid scale factor: %d; must be 1-8\n"

"Error: No input file specified\n"

"Error: No output file specified\n"

"Error: Multiple transformations specified\n"

(File errors are handled for you by the provided pbm library.)Implementation and Submission Details

You must implement ppmcvt according 代 写PPM Image Transformationsto the specifications given above. Youare given skeleton files, ppmcvt.c and pbm_aux.c, in which to place yoursolution code. You may add helper functions to these files as you see fit.You should do your testing from within you “priv” directory.

- Create an empty subdirectory, and copy pbm.c, pbm.h, and Makefilefrom /home/cs350002/share/labs/lab0 to it.

- DO NOT ALTER those files

- copy Your ppmcvt.c and ppm_aux.c into that directory

- typing make should compile your ppmcvt for testing.

-you can test your ppmcvt against the reference ppmcvt provided.There are some sample image files in the Image directory.Start off with the small samples. You can also create yourown samples and even share with classmates.When you are ready to submit create the lab0 subdirectory of cs350

(ie /home/YOURID/cs350/lab0) and copy ONLY your ppmcvt.c and pbm_aux.c

there.

The PBM Library (partially provided)The given PBM library (pbm.h and pbm.c) does the following:

  1. Defines structs for PBM, PGM and PPM image types;
  2. Defines I/O routines to read/write the images from/to PBM, PGM andPPM files.
  1. (Note: The read routine does not handle image files withembedded comments.)
  1. Declares memory allocation/deallocation routines for PBM, PGM andPPM structs.
  1. You must implement these routines in pbm_aux.c.

Image File Formats

PPM, PGM and PBM files are simple (and inefficient) ASCII text file imageformats comprising a small header followed by integer values that represent

each pixel in the image. Wikipedia has a good description here:

https://en.wikipedia.org/wiki/Netpbm.

age TransformationsYour program should produce exactly the same output images as mine. Myprogram uses floating point arithmetic for all intermediate calculations thenconverts the resulting floats to integers as appropriate.Bitmap:

To compute black and white bits from RGB pixels use:Average( R+G+B)<PPMMax /2

Grayscale:

To compute grayscale pixels from RGB pixels use:

Average (R+G+B)

×PGMMax

PPMMax

Isolate:

For all pixels, set all but the specified “red”, “green” or “blue” channel to

Remove:For all pixels, set the specified “red”, “green” or “blue” channel to 0.

Sepia:For the sepia transformation, compute RGB pixels as follows:

NewR=0.393 (OldR)+0.769 (OldG)+0.189 x (OldB)

NewG=0.349 (OldR)+0.686 (OldG)+0.168 x (OldB)

NewB=0.272 (OldR)+0.534 (OldG)+0.131 x (OldB)

Mirror:

Vertically reflect the left half of the image onto the right half.

Thumbnail:

The height and width of the output thumbnail should be 1/n the height andwidth of the original image, respectively, where n is the input scale factor.Shrink the input image simply by outputting every nth pixel in both

dimensions starting with the first.

Nup:

Tile n 1/n scale thumbnails, where n is the input scale factor. The output

image should be the same size of the input image.Requirements and ConstraintsThis assignment aims to make you familiar with some ‘C’ programming

basics. As such, we impose several requirements and constraints on yourimplementation:

  1. You may not modify pbm.h nor pbm.c: you will not submit these files.

We will compile your solutions using our original versions of these files.

  1. You must use getopt() to process your program’s command line

inputs.

  1. You must use the provided pbm library (described below)
  2. You may use only the following library or helper functions:
  3. C Memory Allocation: malloc(), realloc(), calloc(),

free()b. Command line parsing: getopt()

  1. Other: fprintf(), strtol(), strcmp(), exit()
  2. PBM library
  3. Intermediate storage: You must use dynamically allocated memory to

store any intermediary image data. That is, you may not createtemporary image files nor use static arrays (for example, intimage[MAXHEIGHT][MAXWIDTH]). Instead, you should create an arraylike: int **image and dynamically allocate the precise memoryneeded depending on the image size.

  1. You must free dynamically allocated memory immediately when no

longer needed.

标签:files,Transformations,Image,PPM,file,pbm,ppmcvt,image
From: https://www.cnblogs.com/qq---99515681/p/18409927

相关文章

  • WPF datagrid datagridtemplatecolumn image mouseenter show the image in big windo
    <DataGridTemplateColumn><DataGridTemplateColumn.CellTemplate><DataTemplate><ImageSource="{BindingImgUrl}"Width="200"Height="500"><behavior:Inter......
  • 论文笔记--See through Gradients. Image Batch Recovery via GradInversion
    SeethroughGradients.ImageBatchRecoveryviaGradInversion\(W^{FC}\in\mathbb{R}^{M\timesN}\),其输入为一个M维向量\(v\in\mathbb{R}^M\),\(\DeltaW^{FC}_{m,n,k}\)是损失函数对全连接层\(W\)的导数。对于一个特定的类别\(n\),(\(z\)为全连接层输出的logits),其......
  • 论文精读-U-KAN Makes Strong Backbone for Medical Image Segmentation and Generati
    论文链接:https://arxiv.org/abs/2406.02918 论文代码:https://yes-u-kan.github.io/一、参考文献[1]LiC,LiuX,LiW,etal.U-KANMakesStrongBackboneforMedicalImageSegmentationandGeneration[J].arXivpreprintarXiv:2406.02918,2024.[2]LiuZ,Wan......
  • GEE错误:Image.select: Band pattern ‘BQA‘ did not match any bands. Available ban
    目录错误原始代码Landsat8TOA数据介绍错误解析正确的代码 结果错误Errorinmap(ID=LC08_044034_20130603):Image.select:Bandpattern'BQA'didnotmatchanybands.Availablebands:[B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,QA_PIXEL,QA_RADSAT......
  • 智能提取:OfficeImagesExtractor让文档图片提取更简单
    “科技是国之利器,也是民之福祉。”在数字化办公日益普及的今天,我们对文档处理的需求也在不断增长。尤其是对于Office文档中的图片、视频和音频等多媒体内容的提取,传统的方法是繁琐且效率低下的。在这样的背景下,一款能够高效、高质量提取Office文档中多媒体内容的工具显得尤为......
  • 使用Blip的预训练好的imageEncoder并替换其textDecoder
    fromtransformersimportBlipProcessor,BlipTextConfigfromtransformers.models.blip.modeling_blip_textimportBlipTextLMHeadModelfromtransformersimportAutoTokenizermodel=BlipForConditionalGeneration.from_pretrained("huggingface.co/Salesforc......
  • [Docker] Docker Images with Docker
    Soit'smucheasiertodowhatwedidwithDocker.Runthiscommand:dockerrun--interactive--ttyalpine:3.19.1#or,tobeshorter:dockerrun-italpine:3.19.1Abiteasiertoremember,right?ThiswilldropyouintoaAlpineashshellinsideof......
  • 利用深度学习实现验证码识别-4-ResNet18+imagecaptcha
    在当今的数字化世界中,验证码(CAPTCHA)是保护网站免受自动化攻击的重要工具。然而,对于用户来说,验证码有时可能会成为一种烦恼。为了解决这个问题,我们可以利用深度学习技术来自动识别验证码,从而提高用户体验。本文将介绍如何使用ResNet18模型来识别ImageCaptcha生成的验证码。......
  • ndk集成stb_image.h
    一、概述使用步骤:1.在ndk入口cpp中加入一个宏。ps:最好加最上面#include<jni.h>#include<string>#defineSTB_IMAGE_IMPLEMENTATION2.在使用的时候导入头文件//导入stb_image头文件#include"stb_image.h" 二、代码示例stbi_load......
  • Transfusion: Predict the Next Token and Diffuse Images with One Multi-Modal Mode
    Transfusion:PredicttheNextTokenandDiffuseImageswithOneMulti-ModalModel(2024,8)PaperTODO:目前没有开源代码,实时关注一下officialcode,Meta的工作基本开源的.本文给出了一种新的T2I的方法.lucidrains的代码本质是将LLM的transformer和图像中的diffusion结......